How to prevent script instances from overriding default global variables set in the script?

Without making all the variables private and then having to make tons of Get functions, and switch the inspector to debug mode to view values during gameplay. If I save a new value in a script, Unity should update all script instances. Especially if it's just one. How to make the scripts static somehow? It's gonna be one script instance per each script anyway (main player object with a few scripts here and there).

You could set the values of your member variables in Awake().

var foo : float;

function Awake(){
    // Ignore inspector setting and use scripted value instead.
    foo = 4.0;

What you want are public member variables for script access but you don't want the editor to access them.

There's a built in way to do this, just set the attribute HideInInspector.

For Javascript you'd just preface the variable with @HideInInspector. In C# you'd prefix it with [HideInInspector]. (Granted, in C# you'd probably use properties instead of public variables.)

The question body is too confuse. So I’ll answer just the title.

In csharp, simply use internal instead of public:

public bool aPublicBool = true; // you may change this in the inspector
internal string likeAPublic = "ok"; // can only be seen on the Debug inspector

old answer

If you set the value for a variable on the script and outside any function, those variables that will be available on, that’s the default value. When you add the script to some object, it will use those values.

When you do that, the instanced script will be saved in the project with those values. So, if you later change the script default values, the old ones will persist.

If I understand right, you want to override this setting. I highly doubt there’s any simple way to do that.

But you can set all variables to private, save the script so the inspector will remove the variables, then set it back and save the script again. No need to create get functions at all.

Why set/change a value in the script at all? Just set it only in the Inspector.