Hi
I would like to have a global variable that I can access from all scripts in a scene edit / update it.
Any ideas?
Thanks, Chris
Hi
I would like to have a global variable that I can access from all scripts in a scene edit / update it.
Any ideas?
Thanks, Chris
You can find such information in the Script Reference under the section "Global Variables" (Link to Script Reference)
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;
}
//usage
void Start ()
{
SceneData.soundManager=GameObject.find ("sound");
}
void Update()
{
SceneData.width=time.time;
}
you can use sceneData class in any script in any gameObject.