Quantcast
Channel: Answers for "Global variables questions"
Browsing all 10 articles
Browse latest View live

Answer by UdevMike

C# example: public static int myVar; Access it by writing the name of the script followed by the variable name myScript.myVar = 5;

View Article



Answer by Eric5h5

Don't use static unless you only want one instance of the variable. Making a variable public makes it global, static has nothing to do with it (private variables can be static)....

View Article

Answer by karl_

You can access local variables by creating an instance of the script. As an example, lets say you have someVariable located in scriptA, which is attached to gameObjectA. You want to access it from...

View Article

Answer by Peter G

FALSE a static var is *NOT* a global var. `public` makes a variable global, not static. //This is perfectly legal private static int myPrivateVar; static makes a variable a class variable (its a little...

View Article

Answer by Cawas

Use [`Singleton`][1]s! ==== They're [**much** better than using static][2]. Grab the singleton script above and simply use it as such: public class MyClass : MonoBehaviour { void Awake () {...

View Article


Answer by UdevMike

C# example: public static int myVar; Access it by writing the name of the script followed by the variable name myScript.myVar = 5;

View Article

Answer by Eric5h5

Don't use static unless you only want one instance of the variable. Making a variable public makes it global, static has nothing to do with it (private variables can be static)....

View Article

Answer by karl_

You can access local variables by creating an instance of the script. As an example, lets say you have someVariable located in scriptA, which is attached to gameObjectA. You want to access it from...

View Article


Answer by Peter G

FALSE a static var is *NOT* a global var. `public` makes a variable global, not static. //This is perfectly legal private static int myPrivateVar; static makes a variable a class variable (its a little...

View Article


Answer by cregox

Use [`Singleton`][1]s! ==== They're [**much** better than using static][2]. Grab the singleton script above and simply use it as such: public class MyClass : MonoBehaviour { void Awake () {...

View Article
Browsing all 10 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>