Hello, I wrote a script to delay the animation of one game object. I have several game objects moving down the same path, but they are moving at different times. There is something that isn’t right in the script because it does not work the same way each time the game is played. Any help is very appreciated. Thanks.
function Update ()
{
var move = Time.fixedTime + 1;
if (move == 8)
{
animation.Play(“MoveShip”);
}
}
That can’t work because Update runs every frame, and since the framerate will vary depending in circumstances, adding a fixed amount to a variable every frame will have different results when the framerate varies. Also Time.fixedTime is when the last FixedUpdate started and isn’t anything you’d use here. You can use Time.deltaTime where appropriate, and overall you’re much better off using coroutines instead of Update when it comes to things that need delays and don’t run every frame.
–Eric
Thank you for this information. I looked up what you provided in the scripting reference to see how to use coroutines.
Using coroutines…
function Update () {
animateShip(8)
}
function animateShip (delaySeconds : int) {
yield WaitForSeconds(delaySeconds);
animation.Play(“MoveShip”);
}