Animation trigger reset before starting animation
In my game I set the trigger to start the attack animation, run the attack code, then reset the trigger. That gets processed too quickly though and the animation never starts. Although not resetting after function leads the animation to get stuck in triggered state.
Answer by Zoogyburger · Jan 31, 2017 at 06:34 PM
Hi! I found the IEnumerators work very well in this case since you can use Wait for seconds to delay it a bit so the animation will play. Here's an example:
Animator anim;
private float timer = 1;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.A)) {
StartCoroutine (AttackOne(timer));
}
}
IEnumerator AttackOne (float timer){
anim.SetBool ("attacking", true);
yield return new WaitForSeconds (1);
anim.SetBool ("attacking", false);
Debug.Log ("this is running");
yield break;
}
}
Hope this helps!
Thanks! I was looking into timers but I didn't quite know how how to approach this properly.
Your answer
Follow this Question
Related Questions
Mecanim animation playing once on button press 2 Answers
Check for collision while animating 0 Answers
Can't trigger animation on Collider2D 0 Answers
Help with a door slam trap 0 Answers