random animations playing!

*hi guys!
my character has got tow “Idle” animationclip.
one of them is the main an other one should play randomly!
My own script looks correct(i hope)! but my Unity immediately crash when i use it!

	void Idle()
{
	while (Standing)
	{
		if (Random.Range(0,10) > 1) 
			StartCoroutine(Idle1());

		else 
			StartCoroutine(Idle2());
	}

}

it crashes because you do not have any yield in your while loop. So it just keeps running the loop and nothing else. and loops it over and over.

try a yield WaitForSeconds(duration of the animation); at the end, inside of the while loop.

Make sure that your gameobject with animation has a empty parent whose position is 0,0,0.

No one can help me!?

if u mean something like this, i’v tested it! but still doesn’t work! :frowning:

IEnumerator RandomIdle()
{
while (Standing)
	{	
		if(Random.Range((1,10) > 1)
			{
				animation.CrossFade("Idle");
				yield return new WaitForSeconds(animation.clip.length);
			}
		else
			{
				animation.CrossFade("Idle2");
				yield return new WaitForSeconds(animation.clip.length);
			}
	}
}

void Idle()
{
    StartCoroutine((RandomIdle());
}

can u help me n correct my script!?

of course in this one (last one) unity doesnt crash anymore, but there is no delay (yield) between idleS animations! :-?

Finaly i could solve it!
The reason was that “yeild” actually shouldn’t use in Update or FixUpdate,
the correct script is :
(I’ll put it here .for someone who has got the same problme as me! (; )

private float Rnd = 4f;
	public IEnumerator Start() 
{
	yield return 0;
	while(Standing)
	{
		Rnd = Random.Range(0,10);
		yield return new WaitForSeconds(animation["Idle"].clip.length);
	}
}

void Idle()
{
	if(Rnd < 2)
		animation.CrossFade("Idle2");
	else
		animation.CrossFade("Idle");
}