Im having 2 pressure plates, both needs to be activated to destroy a Door.
Why arent my scripts working?

DestroyDoor.js

#pragma strict
var box1 : GameObject;
var box2 : GameObject;
var door : GameObject;
var pressurePlateApressed : PressurePlateAScript;
var pressurePlateBpressed : PressurePlateBScript;

function Start () {

}

function Update () {

}




function Destroy () {
if (pressurePlateApressed && pressurePlateBpressed){
Destroy(door);
}

}

pressureplateascript (b is the same way)

#pragma strict


function Start () {

}

function Update () {

}

function OnTriggerEnter( box ) {
    if (gameObject.name == "Box") {
        
        Debug.Log("A");
        pressurePlateApressed = true;
    }
}

It will not work because:

  • your second script will not compile
  • your Destroy function is not called at all
  • you will destroy the door if A and B is assign to the first script, whether or not they are pressed is irrelevent

Script 1

#pragma strict
var box1 : GameObject;
var box2 : GameObject;
var door : GameObject;
var plateA: PressurePlate;
var plateB: PressurePlate;
 
function Start () {
 
}
 
function Update () {
   Destroy();
}

function Destroy () {
   if ( plateA.pressed && plateB.pressed ){
      Destroy(door);
   } 
}

PressurePlate.js

#pragma strict

var pressed : boolean;
 
function OnTriggerEnter( other : Collider ) {
    if (other.gameObject.name == "Box") {
        pressed = true;
    }
}   

Irrelevant, but still important

You should work harder on your programming skill if you are going to keep on doing this.


You have a pressureplateascript and a pressureplatebscript, and they have the same behaviour, then why not use the same script for both A and B?

If I have 8 bots in a death-match and each bots have a revolver and a rifle, does that mean I have to write 24 different scripts?


In your pressureplateascript, you have a pressurePlateApressed in the OnTriggerEnter(), but you never define it in the script. Your script will not compile.


You have a passable logic in your Destroy(), but you never call that function at all, of course it wouldn’t work. Not using a function is almost equal to not writing one, just that the latter doesn’t waste the programmer’s time and effort.


It is better to be harsh to you right now, it will make you start learning on the basic; I did this so that you will not shoot yourself in the leg when you start to work on scripts that is much more complex.