- Home /
global variable need advice
can global variables be used for all objects in the hiearchy?
for exapmle, can you make something like:
global var x=0
and use that same variable in a different script for a different game object? i just need a yes or no. thanks.
Comment
Answer by Peter G · Feb 20, 2011 at 02:29 PM
You can access variables in other scripts yes.
var someValue = someGameObject.GetComponent.<SomeScript>().someVariable;
or if you need a class variable:
var someValue = SomeClass.someClassVar; //Class var is a `static` var
Your answer
Follow this Question
Related Questions
Using a button to select an object set as a variable. 2 Answers
pragma strict issues with iOS 1 Answer
Passing position to function 1 Answer
How do you achieve variables and functions that are global between scenes? What is the BEST way? 1 Answer
how to make a script when u collide with an object it disappears 3 Answers