} } public class TaskObj { public Action action; public float needTime; public float currentTime; public Transform transform1; public float execFrame = 0.1f; public Transform transform2; }
public IEnumerator loopExec(TaskObj taskObj) {
while (taskObj.currentTime <taskObj.needTime) { taskObj.action.Invoke(); yield return new WaitForSeconds(taskObj.execFrame); taskObj.currentTime += taskObj.execFrame; } yield return null; } public Coroutine startTask(TaskObj taskObj) { return StartCoroutine(loopExec(taskObj)); }
public class TestLookAt : MonoBehaviour { // Start is called before the first frame update public GameObject gameObject1; public GameObject gameObject2; void Start() { postRotateLookAt(gameObject1.transform, gameObject2.transform,3); }
// Update is called once per frame void Update() {