Search Unity

Cannot reset animator trigger

Discussion in 'Scripting' started by Rob-161, May 27, 2017.

  1. Rob-161

    Rob-161

    Joined:
    Dec 1, 2016
    Posts:
    20
    I am having problems resetting an animator trigger. Here is my script:

    Code (CSharp):
    1.     void Update ()
    2.     {
    3.         stunObject.SetActive (unit.IsStunned () && unit.HP > 0);
    4.         if (stunObject.activeSelf) {
    5.             GetComponent<Animator> ().SetTrigger ("Freeze");
    6.             Debug.Log ("freeze");
    7.         }
    8.         if (unit.HP <=0) {
    9.             GetComponent<Animator> ().ResetTrigger ("Freeze");
    10.             GetComponent<Animator> ().SetTrigger ("Destroy");
    11.             Debug.Log ("unfreeze and destroy");
    12.         }
    13.     }
    When the unit is stunned the stun object becomes active and the "Freeze" animation plays. This works fine. If unit's health (HP) equals or is less than 0, I want to reset the freeze animation and play the destroy animation. The actual debug log works but the animation becomes stuck in the Freeze state. Any suggestions??

    Thanks