How would I set it up so when a bullet hits an npc it makes just that one npc disapear. Right now when I shoot an npc it destroys every single prefab on the screen and can’t figure out why. Should I have the code to destroy the npc as a component to the npc or the bullet?
using System.Collections;
using UnityEngine;
class NPCAI : MonoBehavior
{
public void OnCollisionEnter(Collision e)
{
Destroy(e);
}
}
You could set up a simple collision detection like this, that tells it to only destroy the particular object it’s colliding with. Just add some logic to determine whether or not it’s colliding with a bullet.