- Home /
Question is not specific to Unity and already answered on general programming forums
Making Everything Public
I'm new to unity and programming and was wondering what is the reason for not making every variable public. Since public allows stuff to be more accessible why do people make vars private?
When code projects get a little complex, it can become like a web of interacting scripts. $$anonymous$$aking changes and building on that is really hard. $$anonymous$$aking things private reduces that problem. You actually want to make things inaccessible, because that usually means the interactions between scripts are more abstracted and easier to understand in a month.
You can make private fields show up in inspector by for example [SerializeField] private float x = 0;
The inspector complains if you don't set things to an initial value sometimes, usually null.
This question is not specific to Unity. It's a general OOP question which does not belong to Unity Answers.
Without mentionning that OBVIOUSLY, you are not the first one asking this kind of question
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Vuforia Target Image scene not appearing in game 0 Answers
How do I Open/Close my option menu with one key C# 1 Answer
How to create a trigger stopping audio in Unity 1 Answer
Unity 2020.3.21f1 running slow 2 Answers