Unity Inheritance and Monobehaviour
Hi,
I have three classes 'Building', 'Residential' and 'Business'. The 'Building' class does not inherit from anything and the 'Business' and 'Residential' classes inherit from the 'Building' class, which specific functionality added to each based on the type of building, so for instance the 'Business' class has methods to calculate profit.
I have just created a 'Bank' class which inherits from monobehaviour so i can attach it to the bank model gameobject but i want it to inherit the functionality from the 'Business' class.
I have never really used OO programming with unity, whats the best way to structure my classes for inheritance ?
Answer by Trevdevs · Sep 24, 2016 at 03:28 PM
Im no professional at it either mainly because I hardly ever have a reason to use it but this is basically what your trying to do, However you cant have object inherit from 2 or more classes so making them public is the best option id recommend you watch this unity has some amazing tutorials https://unity3d.com/learn/tutorials/topics/scripting/inheritance
public class Building {}
public class Business : Building {}
public class Residential : Building {}
public class Bank : MonoBehaviour
{
Business. //Whatever you need to reference
}