Trying to understand a scripted programming environment

I’m new to the whole individual scripts in a WYSIWYG editor style of programming, and I’m used to your standard procedural and OOP C/C++ paradigms.

With that sort of programming environment I would often have quite a few global variables that I use to store information that will be used by the methods of all sorts of classes throughout the entire project. Stuff like game state and that sort of thing.

With Unity, would I just have a gameobject whose only component is a script that contains these “global” variables? In other scripts would I be able to access and modify that script’s variables, or would each script that wants access have to have its own copy of the variable to read the data into and then communicate any changes back to the “master global variable list?”

Sorry if I’m way off or if this is well documented… I’ve been reading over the docs for the past few days and this question has continued to stump me.

The easy ways , as you thought, is to create a gameobject with a script ie Globals and have the vars/functions declared as static making them global.

EDIT I was using js in example might be done same in c# but not sure.

Little better example for a C/C++ person

make a new C# script an make all variables and functions static if you want to make them global

class CGlobals {
   public static float omgfloaterthigy = 0.0f;

   public static void FunctionfromHell(){
      Debug.Log("(>^-^)> kirby approves of this example");
   }
}

pretty easy huh :slight_smile: ?