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 doesnt work fine!
Its not clear from your code - does that coroutine only get started once, or is it possible it’s being run over and over again giving you a situation where your character is constantly crossfading between 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! (; )
Step through the code in your mind… You start, and while your standing, start, and wait for the idle animation to finish, then go to the next instruction.
What this means is that if you want to walk. Your idle animation will still be running, until the loop is over.
I am sure someone here has done this before, or there is a different way to do it. You would have to write a very large animation handler to CrossFade animations for events. It may just be part of the work for doing animations.
You would have to write something that would run an idle loop, CrossFadeQueued the next animation. Play it at the end if it is not an interrupting animation or play it now if it is. Then return to the looping idle animation if nothing else is happening.
Keep in mind, that your character could be idle, or walking, running, attacking, shooting, jumping, falling or a whole host of other things.
You were right!
It still has problem.
But there is some NEW issue, “Rnd” in first running creating well !(cuose its Start/Awake void)
it means in game starting both idleS work well until the second time ,when State change or retrun to Idle (cuose its Start/Awake void)
“Rnd” wont change anymore, and the animation is playing is the last one!
I’v been searching a lot about it so far!
and only this one is close to my case : http://answers.unity3d.com/questions/10243/random-animations.html
Im so confused and also intrested about Yield and Coroutine using in unity!