- Home /
How to use of interfaces and inheritance if you have seperated scripts?
How to use of interfaces and inheritance if you have seperated scripts attached to a gameobject?
Don't get me wrong. I understand the normal use of inheritance and interfaces but there is one thing that bothers me,. Since you split up your scripts and add those seperatly to your gameobject, i dont get the use of interfaces and inheritance in unity. For example:
Let's say I have an object ufo that can be controlled and is damageble. Normaly you could implement an interface IDamageble and IControllable if all functionality would be in the class ufo, but actually - to make things nice and clear - I add one script calles damage and another calles controller. There is no base-script for ufo where you could implement those interfaces. Furthermore: even if I would have a base script which implements the interface IControllable (which needs the function input()) I would implement the methode input() in the base script and just toss the call to the controller script.
So whats the propper use of interfaces in that case?
The same with inheritance or abstract. Is it useful to let ufo inherit from a class like SpaceShip? Since I splitted up every functional script like moving, shooting, getting damage how to use inheritance in that case?
For me it looks a bit like either you can have one class-script which inherits and implements other stuff or you have seperate scripts added to the game object via inspector.