- Home /
Question by
Noxury · May 01, 2015 at 11:42 PM ·
animationyieldwaitforsecondsdelay
Loop Animation with delay-variable
Hi everybody, I want to play an animation continiously, but every time with delay between them. I know that corountines are not enabled in the Update-function because of certain performancing issues. However, my code do not work correctly ass it should:
public var delay : int = 15;
function Update () {
Platform();
}
function Platform() {
GetComponent(Animation).Play("Platform");
yield new WaitForSeconds(delay);
}
The problem here is that it does not wait the WaitForSeconds-command, so the animation is looping straight after its end without any delay between it.
Any suggestions? Thanks in advance.
Comment
Best Answer
Wiki
Answer by LT23Live · May 02, 2015 at 01:06 AM
ok for one. you need to set a bool in there to turn on and off the function. next your delay needs to be a loat and wrote like below finally you need an animation length. Sorry I dont write java but this should be right!
public var delay : float = 15.0f;
public var animationLength: float;
var functionOn: bool;
function Update () {
Platform();
}
function Platform() {
if (functionOn == false)
{
functionOn =true;
GetComponent(Animation).Play("Platform");
yield new WaitForSeconds (animationLength);
GetComponent(Animation).Stop("Platform");
yield new WaitForSeconds(delay);
functionOn = false;
}
}