Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Need help destroying my enemy when he is killed

$
0
0
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; } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>