Implementing an Interface and MonoDevelop? C#

Is it possible for a class to implement an interface and MonoDevelop in C#? I have a set of characters playable, each one with their one movement script with different methods, but there are a handful of methods that are the same across the board, that although work differently, have the same arguments and do the same thing. Is it possible to implement both an interface and MonoDevelop so that the movement script can be found using the generic function getComponent? Additionally, because the movement interface cannot use MonoDevelop it cannot be converted, or so it seems, to a UnityEngine.Component, so it cannot be used.

Of course you can implement interfaces. No idea what you on about implementing MonoDevelop, but i assume you mean MonoBehaviour,

public class YourClass : MonoBehaviour, ISomeInterface {

}

When you say MonoDevelop I assume you mean MonoBehaviour :slight_smile:

You can implement any number of interfaces but you can only derive from a single class (which makes sense). However, GetComponent constraints T to Component types (as you mentioned). Probably the best way to do this is to do your Interface(s) and then create an abstract class that implements those methods and derives from MonoBehaviour. Then create concrete classes that derive from this abstract class. This will allow you to use GetComponent against the abstract class as a generic “catch-all”.

The other option is to create an extension method on GameObject that will check for interface implementations but this involves getting all attached components and checking one-by-one which has the potential to take too much time (and also isn’t as elegant of a solution).