How I implemented the Skill System in Unity | Using Objects in Unity
In our game I had to implement a skill system, which would allow the player to easily downgrade their states, and also in return enable them use their super abilities and manager their cool downs. Off course, you could just create endless of variables in the PlayerController MonoScript, however doing that is not really the way this should be tackled.
Also I do have to say, that my solution is probably not the best one out their, however it worked like a charm and was very nice to work / implement it.
I do heavily think that Unity is way more then scripting which is most off the time mistaken taken the amount of people that start learning programming with Unity and do not get introduced to advanced mechanics that languages like C# do have to offer.
So here is what I did:
Creating a new Class, which does not derive from MonoBehaviour. That way we can create a sort off memory object and reference it in our player. I called it SkillState:
SkillState manages all the different Category's off Skills our player has. As we see we do have 5 different skills for this game:
Movement
Health
Vision
Damage
Attackspeed
If we now feel the urge to implement a new skillgroup, just add a new object to the array and we are fine!
No we have created a Array off SkillSets, however, what is a SkillSet? This now basically contains all the variables and methods we need to manage all stats:
(Please ignore the fact that we don't have any getter / setters here, but you know the clock ticked ...)
Now we have grouped every value we could need in our player to manage the abilities that we will later implement in the PlayerController. Also what is pretty neat is that we can also implement methods in our SkillSet class, which we can use to make for example the cooldown management very easy.
For example if we now see in the PlayerController Update function, that our desired key was pressed, we can call skillStates.damage.normalReady() and if true we will launch our fireball.
Also as shown in the first picture, when initializing the SkillSet objects, we hardcodeded our balance values. That way we have everything at one place and can easily adjust them later. (Might should shift that in a separate file for larger projects)
Thanks a lot for reading all this and I hoped it made sense what I have written. If you liked it you can let me know and I will write about how I implemented the multistate character.
Also if you now want to see how all this look ingame, you can have a look at our game "SkillSacrifice" we made for LD43.
https://ldjam.com/events/ludum-dare/43/skill-sacrifice
Have a nice day!