I have already made a thread about this but I am still having issues. What I want my script to do is to destroy an object (gate) when the player touches another object (switch,lever,button,ect). The script that one person gave me was this.
#pragma strict
//door script.
var door : GameObject;//apply your door as this varible.
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "Player")//the player must be tagged as "Player"
{
door.active = false;
}
}
Now, when I used this script nothing happens. It compiles but when I collide with the switch nothing happens. I messed with triggers, ridgidbodies, and did some tests which involved making other objects tagged as player hit the switch but still nothing. Can someone please help.
I have Unity 3.5.6. I tried adding the script you gave me but I get two errors. One says unexpected (…) at line 21 which does not exist throughout the script and the other says excepting semicolon on line 21 even though there is a semicolon there.
Easiest way to test if you are actually colliding with it is to put a Debug.Log(“Hit”) inside of the collision enter function. If it shows up then you are having another issue if it isn’t then you know it’s something with your collision setup. Most likely you have to have a rigidbody attached to your player or the object you are running into.