Add the [ReadOnly] attribute before a variable to have it show in the inspector but be uneditable.
Note: The [ReadOnly] attribute will only work on serialized variables.
Therefore, the variable should be public or also have the [SerializeField] attribute.