As a beginner with unity and c#, hoping someone can give me some “pointers” (pardon the pun)… I’m trying to set up a dictionary of “pointers” to a series of functions.
So I have something like this:
Dictionary<string,Action> testpointers = new Dictionary<string, Action>()
{
{“test1”, () => Routine_1() },
{“test2”, () => Routine_2() }
};
void Routine_1{}
void Routine_2{}
I want to use the values, the pointers, in things like AddListener etc so I can change things dynamically using my dictionary. How do I get the function/method “label” as an “pointer”. If I do something like this
var showme = testpointers[“test1”] all I get in debug.log is “System.Action”.
as in the example above.
Then I try to use the “pointer”/value in the way I would in Python or whatever by simply grabbing it with the key and dumping it in.
But …AddListener(testpointers[“test1”]) doesn’t work. I get "cannot convert from system.action to unityengine.events.unityaction. What I’m trying to do is set up an array of delegates (I think that’s what c# calls them, as Kurt in post above points out; I just call them pointers) that I can pick out and use (as in example with AddListener) by using the keys as references.