- Home /
"Shared" variables
I come from a java background and I am looking for a 'static' equivalent (e.g. a boolean called gameOver that I can access from all scripts). How am I supposed to do that?
Answer by Bunny83 · Jul 25, 2014 at 09:50 AM
uhm use "static" ?
Like this
//C#
public static bool gameOver;
//UnityScript
static var gameOver : Boolean;
Those are all c-style languages: Java, C, C++, C#, JavaScript. They all share most common concepts and even syntax. Sometimes slightly different.
Well, like static variables work. You just need to use the class name and the static variable name:
SomeClass.gameOver = true;
@Bunny83 and the class can be posisioned any directory?
@Zarkopafilis, you pretty much can as long as it readable(able to be parsed and built) in the asset folder. In c# you can use namespaces, which are same as packages in Java, developers generally match the folder structure to match the namespace/package setup. If no namespace is defined(if in fact you're using c#) then a default namespace is used when everything is built.