- Home /
How to pick up a key in a box?
I want to be able to pick up a key inside the box only when box is opened. So I have already made the scripts to pick up a normal key, and to open the box, but when I put the key inside the box and I add an if statement ( if (door.IsOpen==true) { key.active=false;} the key cant be picked up. The var IsOpen works properly in the door script.
Shouldn't it be key.active = true? So that when you open your box, and the key is active it is avaliable for picking up?
I mean in if statement I have (box.IsOpen==true && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E) { key.active=false;} but the key cant be picked up.
Okay, seems like i misunderstood. Try using the Code Sample button next time when commenting/posting questions with code.
But anyway try debugging your code so you see which parts are executed and not executed. That way you should see why it is not working.
you could also use a raycast check to see if the player can actually see the key, that way you wouldnt need an additional check
Your answer
Follow this Question
Related Questions
door opening 3 Answers
Opening a door with a key 0 Answers
Help with making his work with a key 1 Answer
Using If functions to open door with a key. 1 Answer
How to make 2 doors with 2 diffrent keys 2 Answers