Search Unity

Player animation 'on trigger' not working as intended

Discussion in 'Animation' started by Goroh_, Sep 25, 2019.

  1. Goroh_

    Goroh_

    Joined:
    Mar 3, 2019
    Posts:
    7
    My script is on the player and is looking for a projectiles trigger so I can play the 'damaged' animation. When the projectile hits the player it is destroyed and the bool stays true. I tried using an else statement to keep it false otherwise, but it seems the object being destroyed on the player is keeping the bool to true. Any ideas on how to fix that?


    Code (CSharp):
    1. public class DamageAnimation : MonoBehaviour
    2. {
    3.     [SerializeField] private Animator anim;
    4.  
    5.     private void OnTriggerEnter(Collider other)
    6.     {
    7.         if (other.CompareTag("Projectile"))
    8.         {
    9.             anim.SetBool("playDamage", true);
    10.         }
    11.  
    12.         else
    13.         {
    14.             anim.SetBool("playDamage", false);
    15.         }
    16.     }
    17.  
    18.     /*private void OnTriggerExit(Collider other)
    19.     {
    20.         if (other.CompareTag("Projectile"))
    21.         {
    22.             anim.SetBool("playDamage", false);
    23.         }
    24.     } */
    25. }