Hi, I’m trying to build an ability system, where I come up with a structure that in my main script component, I have a function called “DoSkill()”, and I have would have variable to store an enum SkillType “currentSkill”.
The SkillType is an enum I defined in another script component called “SkillManager”, My SkillManager have a function called FindSkill(SkillType currentSkill).
So I’m gonna call FindSkill(SkillType currentSkill) in my main script component’s DoSkill(), and then in SkillManager’s FindSkill(SkillType currentSkill), this would do a switch statement to find the correct skill function I pre-defined in SkillManager to return. And then in my main script component, I can use the function returned by FindSkill(SkillType currentSkill)
For example: I defined “Vector3 Dash(float currentTime)” in SkillManager, and I defined enum SkillType {Dash}. In my main script component, I want to
SkillType currentSkill = SkillManager.SkillType.Dash;
float currentTime = 0.5f;
DoSkill() {
var theRightFunction = FindSkill(currentSkill); // Where theRightFunction should be Dash(float currentTime)
// And then I can do like this
Vector3 answer = theRightFunction(currentTime);
}
I wonder if I’m able to do this. And how should I write my FindSkill. Thanks