Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(Shooter Animation) how to stop TakeDamage from looping.

Discussion in 'Animation' started by Rsrc10, Jan 4, 2021.

  1. Rsrc10

    Rsrc10

    Joined:
    Sep 2, 2020
    Posts:
    12
    I need to get my enemy to play 1 damage animation per input and wait for the next input to play again .
    here is my code. This is probably a NOOB problem (guilty as charged), but any help through this problem will get me through this one month Game Launch I've placed on myself. Thanks in advance.

    here is my code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Target : MonoBehaviour
    {




    private CharacterController characterController;
    private Animator anim;
    public float health = 50f;
    int currentHealth;

    private void Start()
    {

    anim = GetComponentInChildren<Animator>();



    }
    public void TakeDamage(float damage)




    {
    characterController = GetComponent<CharacterController>();
    anim = GetComponentInChildren<Animator>();
    health -= damage;
    anim.SetTrigger("Hurt");









    if (health <= 0f)
    {
    Die();
    }
    }

    void Die()
    {
    Debug.Log("Enemy got smoked!");
    anim.SetTrigger("Death");
    anim.SetBool("Hurt", false);
    this.enabled = false;





    }
    }