In Unity, a global variable refers to a value or reference that can be accessed from any script, anywhere in the game, without a direct reference
There are three common methods of creating global variables in Unity:
Static variables, while they aren’t called global variables, work in essentially the same way as a global variable would. This is because they can be accessed from any script without needing a direct reference to an instance of it.
Singletons, in comparison, work in the same way as statics, and use a static reference to work, except that they create a global connection to non-global data.
Scriptable Objects are, technically, not global variables, as they are assets. As a result, to use a scriptable object, you’ll need to create a variable of that asset type and then create a direct reference to it. However, even though scriptable objects require a direct reference to work, they can be considered globally accessible. This is because, since they are assets, their data can be accessed at any time, from any script, from any scene in the game.