Hiding properties of a second class in a script, in its children in Inspector

How do I do this?

ScriptA:

public class Class1 : MonoBehavior{
          protected static Gameobject myGameObject;
          public Class2 class2;
}

public class Class2 {
       public  GameObject assignPrefab;
}

and I want only the ScriptA to show property value of assignPrefab in the inspector. Right now it’s showing in every child as well because its variable in Class1 is public. Any way to do something about that?

Thank you in advance

You could write a custom inspector.

There is a [HideInInspector] attribute you can put on variables to hide them in the default inspector, but I don’t think the default inspector will draw subclass variable fields.

Yes it can be done

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class nestedInspector : MonoBehaviour
{

    [System.Serializable]
    public class nest
    {
        [Range (0, 100)][Tooltip ("Example tooltip")]
        public int test1;
        [Tooltip ("Tooltip 2")]
        public string test2;
    }

    public nest expand;

    // Use this for initialization
    void Start ()
    {
      
    }
  
    // Update is called once per frame
    void Update ()
    {
      
    }
}

2915664--215099--nestedInspector.PNG