- Home /
Opening a door while holding a key
I have two scenes here; the first one is where the key is...
public static bool Key1= false;
if(Input.GetMouseButtonDown(0)){
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 200)){
if(hit.collider.name == "Key1"){
Key1= true;
}
}
}
And here is where you go to open the door
if(Input.GetMouseButtonDown(0)){
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 200)){
if(hit.collider.name == "Door2" || Captain.Key1== true){
Application.LoadLevel("Deck");
}
}
}
However, I am being able to open the door without getting the key, how do I fix that?
Comment
Best Answer
Answer by Midas89 · Mar 01, 2013 at 01:56 PM
Have you tried with AND (&&) instead of OR (||) at if(hit.collider.name == "Door2" || Captain.Key1== true){
Your answer
Follow this Question
Related Questions
Opening door with the same key? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Inventory Dragging Item Problem 0 Answers
How can i set the parent of an instantiated object like a weapon to my players hand. 2 Answers