I would like to have a global variable that I can access from all scripts in a scene edit / update it.
Answer by Sebas
Feb 15, 2010 at 01:45 AM
You can find such information in the Script Reference under the section "Global Variables" (Link to Script Reference)
Thanks for your response. Is there a way to reference a Label value from another script? I created a GUI label with something like this: GUI.Label (Rect (100, 25, 100, 30), text) .... how can I retrieve the value stored in it from another script?
answered/edited this in your other question. see this answer http://answers.unity3d.com/questions/4009/how-to-make-a-timer-in-the-game
quick answer here: the label value is nothing but a normal string variable. You simply declare the variable at the beginning of your script as member variable (outside of any functions) and access it through other scripts like described in your other question which I linked in the previous comment.
Answer by Ashkan_gc
Feb 15, 2010 at 05:41 AM
you have two ways to do this. first of all you can access public variables of scripts from other scripts using GetComponent like what sebas said. also you can create a static class and create static variables in it and use them anywhere in your game. simply create a static class and use it's name to get a reference to it.
static class SceneData
static int width=100;
static GameObject soundManager;
void Start ()
you can use sceneData class in any script in any gameObject.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
updating a gameobject variable from another script attached to another object
Is there a Function Callback for when a vairable is altered in the Inspector?
Game Object referencing from another script
Showing a textarea field for a string variable in inspector?
Creating & accessing a function from a diffrent "OnTriggerEnter" Function