Question by
tahanantb · Sep 08, 2016 at 02:19 PM ·
scripting problemienumerator
[ask] ienumerator not work
i have a simple script for play the animation. but i still not know why my code doesn't works.
can you help me? this is my code :
int i = 1;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
StartCoroutine (animation1());
}
IEnumerator animation1(){
while(i==10){
anim.Play ("idle awal");
yield return new WaitForSeconds (2.5f);
anim.Play ("obstacle");
yield return new WaitForSeconds (1f);
anim.Play ("obstacle out");
yield return new WaitForSeconds (4.5f);
i--;
}
}
please help me :(
Comment
Best Answer
Answer by doublemax · Sep 08, 2016 at 02:45 PM
while(i==10)
i is 1 at the beginning, so the loop is never entered.
Try something like this:
IEnumerator animation1()
{
i = 10;
while( i>0 )
{
anim.Play ("idle awal");
yield return new WaitForSeconds (2.5f);
anim.Play ("obstacle");
yield return new WaitForSeconds (1f);
anim.Play ("obstacle out");
yield return new WaitForSeconds (4.5f);
i--;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612092414im_/https://answers.unity.com/themes/thub/images/avi.jpg)