Why is static typing required for access of public JS function or var in Standard Assets

Trying to organize my projects into smaller chunks, breaking things up into individual scripts and putting in Standard Assets. Apparently, to reference them, I have to put a static in front of all the functions and vars in my JS…

  1. Why is static typing required? What does it do, and will it break any existing script functionality (assuming all the new broken-up scripts were once in the same big huge script)?

  2. Why do variables in the same script need to be typed static if called by a static function in the same script?

  3. Why don’t enum’s need the static declaration?

BCE0020: An instance of type ‘GUIElements’ is required to access non static member …

Adding static in front of it doesn’t make it static typing, there’s a huge difference for another day. Do you understand the difference between class and instance variables?

Static makes it a class variable. I can tell you now, you DO NOT want this functionality. It associates a variable with the class instead of with any given instance. It changes a number of things that have to do with the behavior of the field. It is useful for something like Mathf where you want a class to be a container for all the functions and constants related to math.

Instance variables are created whenever you create a new instance of your class. In js terms, that’s whenever you add a script to a game object. The only way to access them is through an instance of your class. That’s why you’re getting that error. It actually says exactly what you need.

Specifically your problem, when you split up your classes, you isolated different variables. Now you need to use GetComponent() to get references to the instances.

value = GetComponent.<SomeScript>().instanceVariable;

If you don’t get it, just do a little searching for static var problems. They pop up all the time and the answer is always the same. Don’t use static vars.