So, in scripting we have all used the MonoBehaviour, but did you know, this is in fact a special script you can access, within this script are a bunch of methods that we use on a day to day basis in Unity Engine itself; Looking at you public void Awake();
But why is this special, the script we create does what is called Inherit from it, this means it is considered a child of. So how can we do this ourselves.
Well funnily enough its rather simple, you would create a script, lets call this BaseCharacter, and set your methods, structs, enums and the likes within. Once your script is as you wish, create another script, delete the MonoBehaviour and write instead BaseCharacter.
I shall show an example of both BaseCharacter and a new script that inherits from it:
using UnityEngine;
public class BaseCharacter : MonoBehaviour{
private string name;
public void Start(){
Debug.Log("This is a parent script");
}
public void SetName(string name){
name = name;
}
}
using UnityEngine;
public class PlayerController : BaseCharacter{
BaseCharacter baseCharacter;
public void Update(){
baseCharacter.SetName(name);
}
}
This example, minimalistic as it is, shows how you can inherit not just events from our BaseCharacter script but also MonoBehaviour through inheritence.
I hope this helps people