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 () { }
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 () { }
Take a look at the reference for OnCollisionEnter. You can see which object you hit if you include Collision:collision as a parameter.
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