in my game i have enemies dropping health when they die...i have a script working to find out when the player collides with the health but my problem is, when the player collides, all the health instances in the scene get destroyed...how can i make it so only the one instance i interact with is the one that gets destroyed...i have the following script attached to the player:
function OnControllerColliderHit(hit: ControllerColliderHit)
{
if(hit.collider.gameObject.tag == "health")
{
Destroy(GameObject.Find("health"));
Destroy(hit.gameObject);
GRENADE_AMMO += 25;
//GameObject.Find("g_count").guiText.text=""+GRENADE_AMMO;
}
}
I tried attaching THIS to the health prefab but it wont even detect the collision:
function OnCollisionEnter(collision : Collision)
{
if(collision.collider.gameObject.tag == "Player")
{
Debug.Log("hit health");
}
}