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?
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?
The link above applies to all types of variables, and functions too.
– Eric5h5It doesn't matter at all what type the variable is. See the examples on that page that use GetComponent.
– Eric5h5you 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 }
– rokyedCan you put this into code?
– Coreyf716this 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
– rokyed