- Home /
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?
Answer by Jeejo · Jun 18, 2013 at 12:01 AM
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!
Your answer
 
 
             Follow this Question
Related Questions
Locked door and key to open it script 1 Answer
Key Item in C# 1 Answer
Open door with key 2 Answers
Interact with doors using a key? 1 Answer
how do i do a simple key door 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                