0

As the title says I want to cancel an animation after I attacked once and the monster lost 10 lives , and run it again if I attack again and the monster loses another 10 lives . I have tried to find the answer already but I couldn't find anything that works . So far I managed to get it to work the first time I shoot , after he loses 10 lives and the animation goes to idle instead of the animation defend. But the second time nothing happens , he just stays in idle . The code should work unless I am missing something?(I still have to add some code (if it was working)).

```
public GameObject monster;
private Animator anim;
public GameObject player;
private Transform player_pos;
private Target target;
private float i = 0;
private float y = 0;
// Start is called before the first frame update
void Start()
{
    anim = monster.GetComponent<Animator>();
    player_pos = player.GetComponent<Transform>();
    target = monster.GetComponent<Target>();
}

// Update is called once per frame
void Update()
{
    if(target.health <= 0)
    {
        anim.SetBool("isDead", true);
    }
    if (target.health < 100 && i<1)

    {
        anim.SetBool("isDamaged", true);
        i++;
    }
    else
    {
        anim.SetBool("isDamaged", false);
        anim.SetBool("isIdle", true);
    }
    if (target.health == 90 && y < 1)

    {
        y++;
        anim.SetBool("isDamaged", true);
    }
    else
    {
        anim.SetBool("isDamaged", false);
        anim.SetBool("isIdle", true);
    }

}

Dani Baba
  • 23
  • 6

1 Answers1

0

For anyone having this issue, I found out how, just replace the parameter type from bool to trigger.

Dani Baba
  • 23
  • 6