- Home /
Question by
brianchan661 · Feb 19, 2014 at 01:35 PM ·
animation problem
animation.Isplaying and waitforsecond(animation.length) not end at the same time
If(Input.GetKey("x")){
animationcounter++;
StartCoroutine(attacting("skillA",animationcounter));
StartCoroutine(movement());
}
In my game, the player character will do the attacking when x is press, and it will call 2 function:
attacting(), which play the animation
movement(), which move the character using .move()
and the code are as below:
public IEnumerator attacting(string skill,int animationcounter){
Debug.Log("att function start");
attackable=false;
transform.GetComponent<animationcontrol>().controlable=false;
Camera.main.GetComponent<cameraControl2>().controlable=false;
animation.Play(skill);
yield return new WaitForSeconds ( (float) animation[skill].length);
if(this.animationcounter==animationcounter){
Debug.Log("att function stop");
attackable=true;
transform.GetComponent<animationcontrol>().controlable=true;
Camera.main.GetComponent<cameraControl2>().controlable=true;
}
}
public IEnumerator movement(){
Debug.Log("movement function start");
while(animation.IsPlaying("secondskill")){
yield return new WaitForSeconds(0.01f);
controller.Move(this.transform.forward*0.03f);
Camera.main.GetComponent<cameraControl2>().followplayerskill();//attach the camera the player for moveing the camera
}
Debug.Log("movement function stop");
Camera.main.GetComponent<cameraControl2>().endfollowing(); //set camera parent back to null
}
My problem is that the Debug.Log("att function stop"); and Debug.Log("movement function stop"); do the display at the same time,
(i.e "att function stop" display earlier than "movement function stop" in the console)
What is the wrong that makes they are not display at the same time?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613134025im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation problem 2 Answers
scripting animation's duration in java 0 Answers
Character has free movement when 'shooting' 0 Answers