why make global variables private?

Basically I’d like to know why not just have ALL the global variables to be just public variables, so you hit the play button and overview all the variables and their behavior, kind of like an amazing variable inspector. I just realized it’d be quite great to have all your script variables shown on the editor, taking out the need for using Debug.Log() whenever you want to check how a variable is behaving.

The only reason I can think for making most my variables private is when I don’t want them to be specified in the editor. It has happened to me that I declare a global public variable with a starting value in the script, but it was given a different value on the editor, and editor overrides the value which was declared inside the script. And if you don’t know it works like that, it can be annoying, because you keep changing the global value inside the script, but it keeps being the value set in the editor.

I’d like to know how you guys manage private/public variables! What are the pros and cons of using private/public global variables?

You can put the inspector in debug mode to do this.

AMAZING!! :0

I understand the need to inspect everything at runtime, but making everything public can be hazardous for your design on the long run. Here’s some info on why you would want to make things private: Information Hiding :slight_smile: