- Home /
My bullets destroys Objects without it hitting it.
In my script I have a void OnTriggerEnter method
void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Bullet") { Destroy(GameObject.Find("Box")); print("THE BOX Destroyed"); } }
I'm trying to get it so my bullets destroy the objects tagged as box, i have multiple of them on my level, but when i shoot my bullets it destroys the boxes, but it doesn't destroy the boxes when it hits the boxes. It destroys them when it my bullets fly out.
player script cause it doesn't work on my projectile script
Answer by hrishihawk · Mar 20, 2018 at 12:52 PM
@Caldera12 Your OnTriggerEnter
method should be on the bullet (projectile script as you mentioned in the comment). And your script didn't work for the first time because you probably did the wrong checks.
//Have this method in your projectile script
void OnTriggerEnter(Collider col)
{
//if the colllided gameobject is tagged with Box then it gets destroyed
if (col.gameObject.tag == "Box")
{
Destroy(col.gameObject);
print("THE BOX Destroyed");
}
}
nothing it just shoots the bullets if i put the code on my projectile