- Home /
How do I put a delay in this?
Hi, I have a problem with my code
if (Input.GetKeyDown (KeyCode.F)) {
Player.SetTrigger ("Punch_Mid_Start");
} else {
Player.SetTrigger ("Punch_Mid_Finish");
if (Input.GetKeyDown (KeyCode.G)) {
Player.SetTrigger ("Special_Move_Start");
} else {
Player.SetTrigger ("Special_Move_Finish");
}
So basically this is code for my fighting game and my special move. The animation plays half way through then jumps to idol. So I want to put a delay between the special move start and finish so that the animation can finish then return to idol I just don't know how.
Answer by highpockets · Apr 11, 2019 at 09:26 PM
I think you should start a coroutine and wait for the length of the animation to start the next one. The code below expects that the animation state is on the base layer. If it’s on a different layer, you would have to change it from 0 to whatever the correct layer index is.
Cheers
public Animator anim;
void Update(){
if (Input.GetKeyDown (KeyCode.F)) {
Player.SetTrigger ("Punch_Mid_Start");
} else {
Player.SetTrigger ("Punch_Mid_Finish");
if (Input.GetKeyDown (KeyCode.G)) {
StartCoroutine(SpecialMove());
}
}
IEnumerator SpecialMove(){
Player.SetTrigger ("Special_Move_Start");
yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length);
Player.SetTrigger ("Special_Move_Finish");
}
Answer by programer717 · Apr 11, 2019 at 09:11 PM
In the animator check to see that there is an exit time from the transitions, and set the exit time value to 1, that should fix your problem. :) @AWilliams5
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Idle animation plays while running (2D) 1 Answer
Why doesn't it get my values? 2 Answers
Multiple Cars not working 1 Answer
Trouble With Animation - Left & Right Walking, Idle States 0 Answers