- Home /
Bullets not killing Enemy
I'm working on a VR shooter which involves shooting enemies with a gun. However the bullets are not detecting collision with my enemy game objects. My bullet script is:
void OnCollisionEnter(Collision coll)
{
Debug.Log(coll);
if(coll.gameObject.name == "Enemy")
{
Destroy(coll.gameObject);
}
this.gameObject.SetActive(false);
}
Is there something wrong with my code or something I didn't add? I'm generally new to both Unity 3D and openVR development.
Does your console say anything about the collision that you're actually hitting something?
It does not. The only thing that does happen is that the bullets are no longer active
Are you sure you have a Collider attached and not a collider2D
Also its better to do case insensitive on name:
if(coll.gameObject.name.Equals("Enemy", StringComparison.OrdinalIgnoreCase))
Also check if the name is actually "Enemy"?
do you get a message in the console from the Debug.Log when the bullet hits?
Answer by alroemo · Jul 29, 2017 at 09:41 PM
Turns out I had "Sphere Collider" disabled for my bullet object. I'm an idiot. Thank you all anyways.
maybe your bullet is trigger, so collision won't happen, make sure it's not trigger,
You should set this as the answer so people know the problem is solved :)