C#C
C#3y ago
Pacrombie

I have a super weird thing I'm trying to do with interfaces

First of all, I apologize for the incredibly vague nature of my question but I'm become obsessed with finding the "best" solution to every problem I encounter. I have IPlayerAbility with an Activate() method and I essentially want Activate() to execute as if it is on the PlayerController object. I had it so that all of the actual body code that made up the logic of these abilities' Activate() methods were actually just in methods on the PlayerController class. The Activate() methods on these abilities simply called the appropriate method on the PlayerController to do what it needed to do. I then refactored it (because I really hated putting everyting in PlayerController) to have it so that every time PlayerController needed to activate an ability, it would pass itself into the method as such: void Activate(PlayerController player) and then called in PlayerController as: ability.Activate(this). But then when I put the logic into the activate method, I would CONSTATNTLY have to put something like player.transform.position ("player." before practically everything). Is there a better way to do what I'm trying to do? Something like having the logic for a function exist in the ability but have it called as if it is in the player controller? I doubt that would be the case, I just hope I'm getting my goal across. Any advice is appreciated! :)
image.png
Was this page helpful?