Static Variables (52412)

I have several ‘if’ statements within my scripts. I would like to use the same boolean variable in all of my scripts.

How can I access a public var in one script when it was created in another?

1 Answer

1

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

The link above applies to all types of variables, and functions too.

It doesn't matter at all what type the variable is. See the examples on that page that use GetComponent.

you just declare your (static var youNameItBoolean=true;) this in the script YouNameIt.js and then you just say in the other script : if(YouNameIt.youNameItBoolean){ do something }

Can you put this into code?

this should make you understand so now i will explain it how it works: so you have a main script where the static variable is , in the others scripts you can call this variable by writing the name of the script and then the dot and then the variable name wheter is an int float string boolean it realy doesn't matter and you can modify it too i hope what did i do there explains it all , cheers