In unity I am aware how to translate and rotate an object and I always do it in the Update function, the problem I am having is that I want a series of translations and rotations to happen in sequence but the only translation/rotation that occurs is the one that I call first in the code, is there any way to do a translation, wait a certain amount of time and then carry out another translation for example. Thanks.
void Update ()
{
if (enemyHit == false)
{
//enemy moving
transform.LookAt(TTarget);
}
else if (enemyHit == true)
{
Debug.Log (enemyHit);
Evade();
}
}
IEnumerator Wait(float duration)
{
yield return new WaitForSeconds(duration);
}
void Evade()
{
enemyHit = playerMovement.hitEnemy;
transform.Translate(Vector3.back * Time.deltaTime * movementSpeed);
Wait(2);
transform.Rotate(0,90,0);
}
I tried using a seperate function but that didnt seem to do anything.
IEnumerator Wait()
{
yield return new WaitForSeconds(2);
}
You may want to start a CoRoutine as well.
StartCoroutine("Wait");
This should allow you to achieve what you're trying to do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.