- Home /
Random.Range
Hey i was wondering why is there no ability to use a custom string as a listener to call a function with the same name. Example
string customString = player.skills[0].skillName; //in this case the string would be called Slash.
//my thought process was that it should know customString is = to Slash and should find the corresponding void to call but i am wrong.
playerSkillButtons [0].onClick.AddListener (() => customString ());
void Slash(){
//do stuff
}
the problem i face is that the skill buttons will remain the same but will change its effects via listeners if the players skill changes in that slot by using the string name of the skill i was hoping to call the method that would hold the same name to execute the skill, Also i could use if statements to check if the skill name is such and such and add the method directly but that seems very code heavy and extremely messy.
All in all is there anyway i can add a listener to a buttons clicked event using a string for the method or making it invoke the method.
Your answer
Follow this Question
Related Questions
How do I make a function not appear on UnityEvents / Button OnClick lists? 0 Answers
Button doesn't work when returning to scene (android) 1 Answer
Creating working UI Button from Script? 1 Answer
PauseButton keeps getting null reference exception 1 Answer
Why won't my function show up in the onClick area of a button? 2 Answers