- Home /
Animation ignores yield and plays next one
I have script,that plays animations according to "tap" value.I wanted to wait for these animations to end before playing next so I have added yield,but it doesnt change anything.Here's Script
void Update(){
timer = Time.timeSinceLevelLoad;
if (tap == 0){
anim.SetInteger ("Yatak",0);
}
if (Input.GetKeyDown (KeyCode.J)){
LastPress = Time.timeSinceLevelLoad;
if (tap > 2){
tap = 1;
}else{
tap++;
}
StartCoroutine(ComboJ());
}
if(timer - LastPress > 1){
tap = 0;
if(timer - LastPress < Atime){
attack = false;
}
}else{
attack = true;
}
}
IEnumerator ComboJ (){
if(attack){
switch (tap){
case 0:
anim.SetInteger("Yatak",0);
break;
case 1:
Atime = 1f;
anim.SetInteger("Yatak",1);
yield return new WaitForSeconds(1f);
break;
case 2:
Atime = 1f;
anim.SetInteger("Yatak",2);
yield return new WaitForSeconds(1f);
break;
case 3:
Atime = 0.35f;
anim.SetInteger("Yatak",3);
yield return new WaitForSeconds(0.35f);
break;
}
}
}
Answer by smallbit · Jul 27, 2014 at 11:38 AM
Would be nice to see your mecanim. I think that you can setup animation to swtich after its finished by adding two conditions in the mecanim transition. One will be the default one that is there after creating transition (Time > x:xx) which will trigger once clip is finished. And other One will be your Integer. This should assure your animation to switch only once clip is finished.
That's how $$anonymous$$ecanim looks:
Idle goes to Yatak1 if Yatak equals 1,then from Yatak1 it goes to Yatak2 if Yatak equals 2,and its the same for Yatak3, and everything comes back to Idle if Yatak equals 0.
Your answer
![](https://koobas.hobune.stream/wayback/20220613155059im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Help needed with scripting an enemy 0 Answers
Camera elements 2 Answers
how to make one script with different animations attached 2 Answers
Trouble with Null Reference in Script 2 Answers