- Home /
Destroy enemy with spotlight
function OnCollisionEnter(theCollision : Collision)
{
if(theCollision.gameObject.name=="Spotlight")
{
Destroy(gameObject);
Debug.Log("Dead");
dead = true;
}
}
This is my code here, i have a spotlight attached to my enemy which acts like a torch, i tested the collider with player and it works fine but for some reason, when i set it to the spotlight, nothing happens at all. Can anyone help me out here?
Comment
Best Answer
Answer by robertbu · Oct 03, 2013 at 05:07 PM
If you are talking about a torch physically hitting your player, then you need to 1) make sure the torch has a collider, and 2) no other collider is occluding the one you are tryint to hit. Insert on line 3:
Debug.Log(theCollision.gameObject.name);
If any kind of collision is occurring, this will be the name of the other game object. If you need a collider, you can add one using the Component/Physics menu.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115240im_/https://answers.unity.com/themes/thub/images/avi.jpg)