[Question] 'Hide' public variables (make them more like private)

Hi there,i have question:
Is there any way to make public variables for storing, mainly game objects (for example Ball) not visable/public?
I know that i can hide them in editor by adding ‘[HideInInspector]’ before declaration of variable, but this will not hide it to scripts.

The core of the problem is whether or not it is possible to create variables (that I need in my code), then dragg in the editor required object to the field variable, then hide it in editor and hide it from other scripts(make it private)?

This is mainly for purpose of good encapsulation of classes that i write

So i search a little bit and find this:
[show-private-variables-in-inspector]

Possible solution:

  • First write smth like this, in the code

    [SerializeField]
    private Ball ball;

  • Then drag ball in the editor to that field
  • After that, just modify this code to:

    [HideInInspector]
    [SerializeField]
    private Ball ball;

If anyone know better solution please share it here :slight_smile: