Answer the question
In order to leave comments, you need to log in
How to restrict access to variables?
The question of restricting access to variables is very worrying, what is the right thing to do?
Now I do this: I write [SeriasableField] over all private variables that need to be displayed in the inspector, if another script somehow uses this variable, then I write a public Get or Set method. Is it worth it to do this or just declare such variables public?
Answer the question
In order to leave comments, you need to log in
This is more a matter of taste, I have seen both options, I also use SerializeField myself, but more often I tend to properties, not methods, but, again, it all depends on the project. I also often saw an approach of the form:
[SerializeField]
private int _field;
public int field { get { return _field; } set { _field = value; } }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question