So, I am making a game... And on that game I have a door and a Key... The door is locked but when you catch the key the door is unlocked...
I have 2 scripts... The script which belongs to the door is Door.js and the script that belongs to the key is Key.js
EmptyObject > Key > Key.js Door > Door.js
In my key.js I have this codes:
public var hasKey : boolean;
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
hasKey = true;
}
and on my Door.js I have this codes:
var openDoor : boolean;
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player" && hasKey== true) {
openDoor = true;
}
Thanks for the help.