Switch Code

I am making am objective of a game where you have to collide with a switch to open a gate. I don’t care about animations right now. All I want is a code to destroy the gate once I collide with the switch. I have gone about this a few ways and failed. Any ideas?

First step is to post this question in the scripting forum. After that, the rest is easy.

Oh but don’t post this again there, wait for a moderator to move this thread.

Well, without code i’d have a variable of the door, then a script attached to the switch (and a trigger) and have on trigger enter and check the tag of the player then if it is the player delete the door… if that didn’t help post and i’ll do code of it.

Yeah, sorry I am not sure how to do that. I am extremely new to coding and I use Javascript. Here is the script I tried but it does not work

var BlueGate = 0;

function Start () {

}

function Update () {

}

function OnCollisionEnter ( BlueGate == 1 ) {

if (gameObject, BlueGate == 1)
Destory (gameObject, BlueGate);
}

//door script. atach this to the switch.

var door : gameObject;//apply your door as this varible.

function OnCollisionEnter(collision : Collision) 
{
if (collision.gameObject.tag == "player")//the player must be taged as "player"
 {
  door.active = false;
 }
}

how is that? note that ether the player or switch must have a rigid body attached.

Well, I tried that but when I added it, it said there was something wrong with gameObject so I just tried changing it to GameObject and it would actually let me add it and test the game. I tried messing with a bunch of things on it and the ridgidbodies but still nothing works.

#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;
 }
}

This is a webplayer I made of the script It works fine, as can be seen when the cube hits the switch it disables the door.

Make sure you player is tagged as “Player”

The code you posted is syntactically incorrect and I’m pretty sure it wouldn’t even compile. I’m sure someone could correct it for you, but I think you’d be better off in the long term spending some more time learning programming in UnityScript

Yeah I don’t know why but still nothing happens. I tagged the player. I tried messing with triggers and rigid bodies. I have no idea what to do.

It says there is a script missing from monobehavior. I think this could be causing me to have problems with the script. Is there any way to fix monobehavior?