What is a good way to do this ability system?

Hello, I’m quite new to Unity and C#. Now the player character in my game has a bunch of abilities like Restore Health, Spin Attack, AOE Attack, Auto Aim, etc. All abilities are functions in PlayerAbilities class attached to the player prefab. Player can use those by defeating a specific number of enemies and the screen will show 3 random abilities from available ones. Player then can press the button to use it.

77277-untitled.png

Now I’m trying to do 2 thing but very confused and not sure what to do.

  1. I’d like to have an icon for each ability, so it’ll be shown on screen when player can use it. But I’m not sure how to put a sprite in a function.

  2. I’d like to do a shop for abilities, so player can use in-game money from defeating enemies to buy new abilities. (Each player character starts with 3 different starting abilities. When they bought new ones, the new abilities will be available (extend the ability pool) and can be randomized to use. I suppose I have to do a list for that, correct?

If anyone could help me and show how the structure of the code involving this system would look like, that’d be so great. I’m stuck with this problem quite a while.

Read up on the use of “delegates” in C#

Your would end up with an ability class that basically had an action delegate and a display icon delegate. Those functions draw the icon and do the action.

On your character you have the delegate function pointer and you call the delegate when you want to draw the icon or do the action. The delegate function on the character can freely be attached to any matching delegate of your choices of ability. So at your shop when you “buy” new spells you simply hook a new delegate function to the character.

That is the simplest clean way to do what you want without getting into class complexities.