ibyte
1
I have GameObject "A" and GameObject "B". They both have a copy of a C# "ScriptX" attached to them as a component. It is my understanding that all variables in each instance of the script are unique to each script.
How can both scripts reference a common variable or what techniques can be used to share common data objects between them?
Mortim
2
You can declare variables as static in order for them to be common to all instances of your class.
You can also make all your instances have a reference to a third-party object which will handle communication between your gameobjects. For example, every object in a chess game can have a reference to a "GameWorld" object which handles the game consistency, check proposed moves against rules and manage every pieces. Usually, this kind of object is a singleton which is declared as a static variable in classes who reference it.