[Solved] How do I use variables in a separate script in Unity3D?


You could make a class, instantiate an object of the class and access propterties.
Or you could use static variables.
Or even beter, lets say you have a GameManager.cs script attached to an empty object called GameManager. And you want to access its variables form the LevelManager.cs script. You do this inside the LevelManager.cs

public GameManager gameManager;

Then you can drag and drop your GameManager empty object to this public field, and everytime you want to access a variable you type gamemanager.yourVariableHere
Or, if you dont want to drag and drop:
in the start method…

void Start()
{
 gameManager = GameObject.Find("GameManager");
 //this way it finds your object automatically
}

Hope it helped, good luck.

1

solved How do I use variables in a separate script in Unity3D?