- Home /
Help with Scripting (Boolean)
I have a public static bool open; which is set weather the door is open or not. This is required as two gameobjects use the script and this makes sure they both know if the doors open or not. It works.
However when I have multiple doors they all think they are either open or closed. Is there any way I can give the doors ID's so in the inspector I could in each button put for e.g. 1. And then for another door and buttons 0.
Theoretically it would work, however I don't know how to implement something like this. Im a expert in C# but that with software and I'm relativity new to unity.
Answer by getyour411 · Feb 22, 2014 at 08:05 PM
give the gameobjects a script with a public variable like
public int doorID;
and then assign it in the inspector. Don't use a static for that.
I've done that but how would I implement that as currently i know for example Door1 open/close ect but theyc still dont know their individual status.
Currently its like Door_F open = true; Door_R open = true; Door_L = true;
It needs to be Door_F open = true; Door_R open = false; Door_R open = true;
For example. So each door knows if its open or not. But as the script runs on two gameobjects this is proving difficult.
Here are my doors Ones Open and the Other Closed. As I opened one they both think they're open so when the closed door is opened via the button it closes... as it has the same static bool.
Note im using animations to move parts of a .fbx model I made.
You're an expert in C#? I don't know what you are asking anymore tbh, using a static as an open/closed flag on multiple doors makes no sense. "They still don't know their individual status" - no clue how to interpret that. If they have a bool setting for open/close, how do they not know their status? Are you really just asking "How do I get the bool value on DoorA (b, c, doesn't matter) from two or more scripts on other Gameobjects?
Such as
Door.cs
public bool doorState;
Script1
...GetComponent<Door>().doorState
Script 2
...GetComponent<Door>().doorState
now both Scripts 1 and 2 'know' the doorState
I have a game object (the junction you see in the image. Its one game object / model. The doors are separate things in this model so can move. I animated a open and closing animation. When the user presses the button (white) the doors need to open if closed and visa versa. The way it knows which doors to open is due to it looking for the Front, Left or Right door animation (corridor splits 3 ways).
Currently the doors don't know their state if you use the button on the other side as using static all doors have the same open value.
If I dont use static each button treats the door individually and you may end up running the open animation several times due to all the buttons starting off with thinking the doors not open. and when another button opens it this button doesn't know that.
The only solution would be to read the variable of the component on the button on the other side of the wall. As I'm new to unity im not sure if this is possible.
I made this it may explain my issue. Thanks, $$anonymous$$.
The value is carried but as both are getting the doors value from each other they always both are false. I will work on finding a way around this.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
rigidbody2D.velocity.y always returns 0 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How to make buttons that will move an object to a certain point based on the characters choice? 0 Answers
Monodevelopement not responding? 2 Answers