Interfaces

I have not encountered ‘interfaces’ before so sorry for these beginner questions.

Sam explained it as saying "I want this method [in this case one called “Take Hit()”] to be implemented on whatever object is passed in [in this case target - which I’m guessing is the Class called “HighCohesionCharacter”]

a) will we be dealing with more use/examples of ‘interfaces’ - if not, could you recommend some resources.
b) how is the varaible ‘target’ given the HighCohesionCharacter class without some form of caching?

2 Likes

Just about any C# book covers interfaces. I’m sure there’s probably a bunch of web pages and youtube videos that will cover interfaces to death.

I’d suggest going and reading a little more on the subject without worrying about Unity. Combining it with Unity will only confuse the issue.

An interface is a sort of a contract. An interface says that any class that implements the interface is guaranteed to have the methods listed in the interface.

This means that objects don’t have to have direct relationships or inheritance to be considered items of a the interface type. All a calling object needs to know is that the item implements that type.

In this instance, the variable target is not actually given any information about the HighCohesionCharacter class at all, except for the pointer to the object itself. In fact, the only methods you can call on target is the TakeHit() method, as it’s the one implemented in the interface.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms