Hey Guys, is there any way or alternative to inherit from multible classes?
Basically I want to have to classes, a player class and a character class, since a character can be also another player I want to inherit the player class from the character class.
Here’s my Code: Character.boo
import UnityEngine
public class Character (MonoBehaviour):
health as single = 100
maxHealth as single = 100
stamina as single = 100
maxStamina as single = 100
def kill():
pass
def respawn():
health = 100
stamina = 100
Player.boo
import UnityEngine
public static class Player (MonoBehaviour, Character):
def Update():
pass
The current error is "Assets/Scripts/Player/Player.boo(3,44): BCE0001: The class ‘Player’ already has ‘UnityEngine.MonoBehaviour’ as its super class.
"
If you derive your Player from the Character class the Player will also be a MonoBehaviour since the Character class os derived from MonoBevhaviour. So just derive your player from Character and you’ll be fine.
.NET / Mono only allow one base class per class, there’s no way around that.
Keep in mind that MonoBehaviour is also derived from Behaviour and Behaviour from Component and Component from UnityEngine.Object. So your complete class chain would look like this:
Player → Character → MonoBehaviour → Behaviour → Component → UnityEngine.Object → System.Object
edit
I just reread your title. You said you want to use multi inheritance but what you actually need is simple inheritance, at least what we can understand from your description.