Can I have a variable accessed through the inspector and be accessed by a child script without making it public?
I have a superclass "Lighting" which is inherited by my child script "Torch", "Sun" and "Campfire".
In the "Lighting" script, I have variables defining the flickering of the light, intensity, color and so on, which I want to adjust individually in each child script through the inspector for ease of testing. However, I do not want to make it public to prevent tampering and such. Is it possible for my child script to access and edit the variable inherited from the parent class while showing the values in the inspector?
Thanks.
Comment
Best Answer
Answer by Hellium · Apr 19, 2018 at 08:11 AM
For sure:
// Lightning.cs
[SerializeField]
protected float intensity ;
//Sun
void Start(){ Debug.Log( intensity ) ; }
Ah I didn't know you could use SerializeField on protected variables as well. Thank you!