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.
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!