I have a working enemy that moves to the player and can be killed but when he is killed he still follows me around so I came up with the idea to have him be destroyed but after looking around the internet for a while I have not been able to find any answers or lines of code that work. I am very new to unity and writing code. So I need some help With my problem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public Animator animator;
public int maxHealth = 100;
int currentHealth;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
}
public void TakeDamage(int damage)
{
currentHealth -= damage;
animator.SetTrigger("Hurt");
if(currentHealth <= 0)
{
Die();
}
}
void Die()
{
Debug.Log("Enemy was killed");
animator.SetBool("IsDead", true);
GetComponent().enabled = false;
this.enabled = false;
}
}
↧