- Home /
destruction on impact
i have this script below to make an object get destroyed on collision, how do i make it so that it only gets destroyed on certain objects??? Thank u for your time :)
function OnCollisionEnter(){ Destroy(gameObject);
} function Update () { }
forgot 2 say that i have explosion prefabs.... :)
Answer by Jules-Fletcher · Feb 13, 2011 at 12:19 AM
Maybe adding tags can help,
function OnControllerColliderHit(hit: ControllerColliderHit) {
if (hit.gameobject.tag == "DestroyableObject") {
DestroyObject();
}
}
then add the DestroyObject function...
Hope this helped,
Jules Fletcher
Answer by engelmannalex · Nov 23, 2010 at 06:32 PM
Take a look at the reference for OnCollisionEnter. You can see which object you hit if you include Collision:collision as a parameter.
Your answer
Follow this Question
Related Questions
Is calling OnCollisionEnter from multiple scripts bad? 0 Answers
How can my character be destroyed upon contact with 1 specific object? 1 Answer
Simple Collision Detection not working. [Solved] 3 Answers
Collision Only being detected on one of the objects involved in the collision - C# 0 Answers
How do Unity manages collisions in a game internally? 0 Answers