Inheriting from a base class that inherits from monobehavior hides Start() in the base class if you use it in the derived class. As well as a lot of other monobehavior functions.
How can I have Start() work in both classes?
Inheriting from a base class that inherits from monobehavior hides Start() in the base class if you use it in the derived class. As well as a lot of other monobehavior functions.
How can I have Start() work in both classes?
This seems to work for me…?
using UnityEngine;
using System.Collections;
public class ManyBase : MonoBehaviour {
public void Update () {
}
public virtual void Start() {
Debug.Log("Hello");
}
}
public class Many2 : ManyBase {
public override void Start ()
{
base.Start ();
Debug.Log ("World");
}
public void OnGUI() {
var style = new GUIStyle();
style.normal.textColor = Color.white;
style.fontSize = 12;
GUI.Label(new Rect(10f, 10f, 2f, 0.5f), "Hello World", style);
}
}
Just remember that a MonoBehaviour isn’t valid unless it defines both Start() and Update(). If your parent class only defines start, and the child does not define Update() its not a valid behaviour and wont be executed.