I'm a bit stuck on my coding.
So I'm making a progressbar, but I'm experimenting with OOP programming in C#.
I have two classes, a CProgressBar and ProgressBar class.
ProgressBar inherits from CProgressBar and gets its variables but I want to make two of the variables in CProgressBar public, but still keep them private in ProgressBar.
I should also mention that this is for Unity3D, hence the RawImg class.
UPDATE: So after some people commented some ways to do this, I feel the answers do not solve my particular issue. I shall re-phrase.
- I would like CProgressBar and ProgressBar to be visible in the Unity editor. One of the answers shows CProgressBar class being abstract, but this hides the class in the Unity editor, so that is out.
- Both mat and rawImg should be hidden on CProgressBar, but shown on ProgressBar.
- The variables don't necessarilly need less access, they just need to be hidden on the base class.
Usage of the [HideInInspector] attribute would be a hack but not sure where to use it.
// public CProgressBar.cs public abstract RawImage rawImg { get; } public abstract Material mat { get; } // public ProgressBar.cs public override RawImage rawImg => null; public override Material mat => null;
If I put [HideInInspector] attribute on the base class variables, it will also hide them on the inherited class. I don't want that.
I guess for now I will have to make both variables public allowing my users to change things that I DON'T WANT THEM TO CHANGE.