Public inventory system

Hi, I am trying to change the value of a script my player is holding when he steps on a key, and then if the player goes to a certain entrance the entrance will check if the player’s script value is equal to true or not. Does anyone have a simple solution to this?

For this you would need a couple scripts, the first one is picking up the key, attach to collider around the key:

PickUpKey.js

var key : GameObject;

function OnTriggerEnter (other : Collider) {
    Destroy(key);
    DoesHaveKey.hasKey = true;
    Destroy(this);
}

This is the script that the door will read, attach to player (or whatever).

DoesHaveKey.js

static var hasKey : boolean;

Then you add this to your door script:

//create a new variable to tell whether or not the door can be opened
var canOpen : boolean = false;
//etc
function Update () {
    //inside of your update function, do something like this:
    if(DoesHaveKey.hasKey == true) {
        canOpen = true;
    }
    if(DoesHaveKey.hasKey == false) {
        canOpen = false;
    }
}

That should work. Hope this answered your question!