Friday, January 27, 2017

c# - Unity: detect animation's end


I need a way to detect if animation's clip finished playing and then execute a certain code. Here's some script, that I wrote (called in Update):


    if (Input.GetButtonDown ("Fire1") && pc_atttacking == false && PlayerStats.staminaCurrent != 0) {
pc_atttacking = true;
pc_anim.SetBool("attack", true);
}


if (pc_anim.GetCurrentAnimatorStateInfo (0).IsName ("attack")) {
pc_atttacking = false;
pc_anim.SetBool("attack", false);
}

But it doesn't work as I want; it executes second code too early - when "attack" animation is at slightly more than half of playing position. I want to execute it when "attack" animation is at last frame.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...