- Home /
Problem with making skill system for my creatures
Hi. I want to make some skill system for my creatures. I see it like that:
Write classes for all skills (they inherit from some abstract base class and I want all skills to perform different action, preferably in coroutines if possible)
Add all of them to some static general dictionary (all skills have unique string id)
Add some default skills to my creatures (let's say i want one of them to have Fireball, Kick, Roar, the other to have Acid, Thunder Bolt, Attract etc.)
And finally let players change specific creature's skills (remove, add, maybe upgrade) in some menu.
I wanted to make it like this: http://answers.unity3d.com/answers/873150/view.html
But i have some questions:
Should i create separate script for every skill? Or can i just have all classes in one script with base abstract class? Or maybe abstract class in one script and all inherited classes in other script?
Do i have to attach skill script with base skill class/inherited skill classes to game object? Because they have to derive from MonoBehaviour if i want to use coroutines (i think)
How and when i should skills to general dictionary?
Or maybe there's better way to do it?
Answer by joshua-lyness · Jul 15, 2016 at 12:41 AM
Its a tricky thing to tackle, since "fireball" probably massively changes the way the creature interacts. I'm doing something similar in a game i'm making, it's a city builder and there are lots of tools such as the road tool, zoning tool etc. These tools are each scripts on a manager gameobject. The manager object also has a manager script. Each of the tool's scripts has an "active" Boolean, and the manager script turns the Boolean on and off. You can do something similar, by having a manager script on each creature, and scripts for each skill on the creature. The manager script can then turn the skill scripts on and off by changing the stage of an "active" Boolean. Just an idea, but it's a solution that would work. :)
But let's say i want to have overall 100 skills and one creature can only have 4 in the moment (but players can swap one skill for another). So i have to add 100 scripts to each creature but mark as active only available ones? Can that have negative impact on performance?
EDIT: or maybe implement some type feature and for example to water type creatures add only water type skills. That's certainly better than adding all of them.
It shouldn't be negative on performance any more than putting it all in one script is, unless you're changing other scripts' variables a lot. The thing with skills is that an entire script might be necessary. Let's say the skill is something like explosive punches, that's going to involve a lot of code, whereas super run wouldn't, that would just change a variable. Either way, if you choose to put it all in one script, having a "selection" class would be appropriate, to control which skills they have. Your best bet might be an array of integers, with the skills each having its own index that the array will hold (so for example if the array had the numbers {1,24,6} in then that might point to skills {jumpHigher, runFaster, timeTravel} or something like that. It's really an open ended question and all I can give you is ideas.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084828im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Combine duplicates in a collection of class objects 0 Answers
Cannot use custom type as key for dictionary 0 Answers
How to refer to object based on value of a variable 1 Answer
rpg, skills and characters the structure, confused 0 Answers
Referencing the object that a construtor is currently constructing/working on. 1 Answer