Hello,
Sorry this question is really simple - I want to make a game object disappear when my player enters a trigger. This is the code I’ve written, but I can’t work out what’s wrong, as although there are no errors - the object doesn’t disappear?
var pylon : GameObject;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Player")
Destroy (pylon);
}
Thanks very much, Laurien
Well, obviously you didn’t attach the script to the pylon in your code. You could do that (but then lose the script when destroying) or you could attach the script to the Player and edit it as follows:
var pylon : GameObject;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "replace_here_with_pylon_tag")
Destroy (pylon);
}
Also be sure to have colliders on both the trigger and the player and a rigidbody on the player.
Hope this helps!