Is it possible to run a method in a script where the method's name is found from a text variable?
For example:
public text MyVariable;
public void Start()
{
MyVariable = RunMeBaby;
MyVariable();
}
public void RunMeBaby()
{
Debug.Log("You did it!");
}
In the above example I'm assigning the variable 'MyVariable' to 'RunMeBaby' (the name of the method I want to call) and then attempting to call it.
The above doesn't work for me, but is there another way?
EDIT TO ADD ADDITIONAL CLARIFICATION BELOW
I am currently creating my own card game. I've created a scriptable object (CardAsset) to handle some fields that all my populated cards will need. Stuff like:
Card Name (string)
Cost (int)
Image (image)
Description Text (string)
I'm now at the point all the other stuff for my prototype is complete (playing field, deck, etc), and I need to start actually making the effects for my cards. Since every card is different but some of the effects are the same (draw more cards and deal damage to a character are very common for instance), I figured I could alter my scriptable object CardAsset to include some scripts and variables:
Card Name (string)
Cost (int)
Image (image)
Description Text (string)
Effect1 (script)
Effect1Amount (int)
Effect2 (script)
Effect2Amount (int)
Effect3 (script)
Effect3Amount (int)
This way, I could create CardAssets with upto 3 effects on them (again such as dealing damage to a character or drawing cards) and then use something in my game to call those scripts with the associated variables when the player plays that card.
My issue is that I cannot attach scripts to my CardAsset, so I figured a suitable workaround would be for me to type in the name of a method (DealDamage, DrawCards) in the Effect1/Effect2/Effect3 slot on the CardAsset (changing them to a string), and then have something read them and call the associated method elsewhere.
I understand that this solution is prone to errors and could be painful to maintain/change, so is there a better way I could do it?