- Home /
Destroy object 1 if player walks into object 2
I have a game i'm designing and i want the player to be trapped in a rectangle box, the player walks to one side and sees a wall, the player tries to go back and sees another wall but i have a an object by the 2nd wall so that when the player walks into the non rendered collider near the 2nd wall it triggers the wall behind them to get destroyed. Heres a few lines that i have tried that did not work.
function OnCollisionEnter(theCollision : Collision){ Destroy(gameObject); }
var desroyObject : GameObject;
function onTriggerEnter(other : Collider){ Destroy(other.gameObject); }
function onTriggerEnter(other : Collider){ Destroy(GameObject.Find("Plane")); }
The object im destroying is a plane and i have the tag set to Destroy1, i am unsure if it is the code or if i did something wrong with my colliders on my player and the trigger. The player has a capsule collider and the trigger has a box collider, both have "Is Trigger" checked as well. please help :(
Answer by 767_2 · Nov 07, 2014 at 03:20 PM
for OnCollisionEnter
one of your objects must have RigidBody attached and Istrigger set to off