Hello... I have a question. I have two classes and two functions: Code (CSharp): public class BaseClass : MonoBehaviour { public void Awake () { //initializing some variable } } public class ClassDerivated : BaseClass { new void Awake () { base.Awake(); Debug.Log ("I have initialized variables and now I print"); } } The BaseClass "Awake ()" function in order to be called with "base" keywork in the derivated class, has to be public? What if I want to set this function private? In my project I have a base function in the base class and a polymorphed in the derivated class which does the previous things more updating a text item and I would like to keep things separated and the first function (the one of the BaseClass) private....how could I do?
Make Awake protected virtual in BaseClass and protected override in ClassDerivated. What you have isn't actually inheriting the functionality of Awake
You have to make your method protected, this way it is visible to the derived classes Code (CSharp): public class BaseClass : MonoBehaviour { protected virtual void Awake () { //initializing some variable } } public class ClassDerivated : BaseClass { protected override void Awake () { base.Awake(); Debug.Log ("I have initialized variables and now I print"); } }