Using Skills
Understanding skill usage.
Using a Skill
When a skill should be used, SkillTree.TryUseSkill
should be called. This will attempt to use a skill if possible. It goes through basic checks to see if a skill can be used. If not, nothing will happen. You wouldn't want a skill to be used while it's winding up or it's on cooldown, right?
This method requires a SkillNode
and UnitStatsProvider
reference. A skill node is required to know which skill was attempted. A stats provider is useful because it will make the skill user's stats easily accessible—more on that later.
This is called automatically with the Default Prefabs. TryUseSkill
returns a UsedSkill
object.
Completing Skill Use
After a skill is used with TryUseSkill
, you need to look to call SkillTree.CompleteSkillUse
. This will tell Skill Tree when a skill's usage has been completed. This does not refer to the entire duration of the skill, but rather just the duration of the skill's animation because you wouldn't want another skill to be used while the previous skill's animation is currently running—unless you do, which is why you're free to call it whenever you'd like.
Used Skill
A UsedSkill
object is, as it sounds—a skill that was used. It handles a skill's windup and cooldown behind the scenes. You can use UsedSkill.skill
to get the SkillNode
and UsedSkill.user
to get the UnitStatsProvider
.
Custom Functions
With the Skill Interpreter component, you can run your own functions when a certain skill is used. Each event in the interpreter accepts a UsedSkill
object. Your custom function can use this to get the stats.
Example
For example, let's say you want to damage an enemy when the "Attack" skill is used. Here's how you could write a function for this:
In the Skill Interpreter component, add an interpreter and give it the key "Attack" (the key of the skill), and then add this function to the On Skill Used event.
This is just an example. The code will greatly depend on your game. Check out the demo scene in the Assets > StylishEsper > SkillTree > Example
folder for better examples.
Last updated