How to: c# public variable not show up in the Inspector?

Getting up to speed on c# and Unity…

In c# is it possible to declare a public variable but not have it show up in the inspector?

I want to do this for public variables that will be set by external scripts and have no need to be in the inspector so I don’t want the inspector to be cluttered by them.

Take a look at HideInInspector.

Public properties won’t show up in the inspector.

public class QuickExample : MonoBehavior
    public float MemberVariable; // this shows up in the inspector

    public float Property { get; set; } // this doesn't show up in the inspector

Other code can refer to properties in a manner very similar to accessing public variables.

QuickExample test = new QuickExample();
test.MemberVariable = 5;
test.Property = 6;

Debug.Log(test.MemberVariable); // logs "5"
Debug.Log(test.Property);       // logs "6"

I encourage you to read up about C# properties, as they’re a very handy tool that C# provides: Properties - C# Programming Guide | Microsoft Learn