Im having 2 Pressure Plates.
Both needs to be activated to open a Door.
I have this Code:
#pragma strict
var door : GameObject;
var box : GameObject;
var boxes : int = 0;
function Start () {
}
function Update () {
}
function OnTriggerEnter( box ) {
if (gameObject.name == "Pressure Plate") {
Debug.Log("Box 1 Added!");
boxes += 1;
}
}
function Destroy () {
if (boxes == 2) {
Destroy(door);
}
}
I attached this to both Pressure Plates.
But it doesnt works???
2 Answers
2
var door : Transform; //That is your door
var PPlate : Transform;
var Plate1 : boolean = false; //Set true if you are No1
var Plate2 : boolean = false; //Set true if you are No2
var hasCollided : boolean = false;
function OnTriggerEnter(other : Collider)
{
hasCollided = true;
}
function OnTriggerExit( other : Collider ){
hasCollided = false;
}
function Update(){
if(hasCollided){
OnOn();
}
}
Its bad sorry, 22:44 too sleepy
Attach this script/code to the Plate:
var door : Transform;
enum Plates {Plate1, Plate2};
var Plate : Plates = Plates.Plate1;
function OnTriggerEnter(other : Collider){
door.SendMessage("PlateCall", Plate);
}
Attach this script/code to the Door:
enum Plates {Plate1, Plate2};
var Plate1 : boolean = false;
var Plate2 : boolean = false;
function PlateCall(Plate : Plates){
if(Plate == Plates.Plate1){
Plate1 = true;
}else{
Plate2 = true;
}
if(Plate1 && Plate2){
Destroy(transform.gameObject);
}
}
This code is untested. I don’t know if it works so well with enums but you could easily change it to booleans, integers, …
and hown do i do that?
– MegaStevenLPBtw. If your question is solved please accept an answer or close the question.
– ExTheSea