Okay in unity I'm trying to use Invoke to call a method given in a string format. I can get it to work with no parameters but using parameters it fails, and I can't figure it.
public string SetCVar(string args)
{
return "hello";
}
public string ParseCmdString(string str)
{
// Find Cmd string
string cmdStr = str.Split(' ')[0];
if(cCmds.ContainsKey(cmdStr.ToLower()))
{
Cmd cmd = cCmds[cmdStr];
System.Type objType = cmd.obj.GetType();
System.Reflection.MethodInfo method = objType.GetMethod(cmd.method, new System.Type[]{typeof(string)});
return (string)method.Invoke(objType, new object[]{str});
}
return "Command not found!";
}
if SetCVar
has no parameters its fine other wise I get the following error.
ArgumentException: failed to convert parameters