在C#中使用字符串调用方法时"对象与目标类型不匹配"

Ber*_*hau 3 c# string reflection methods invoke

我正在尝试使用字符串调用方法,但是有一个问题:

void make_moviment(string mov,Vector3 new_mov){
    GameObject past_panel = GameObject.Find(actual_level.ToString());
    Type t = Type.GetType(past_panel.GetComponents<MonoBehaviour>()[0].GetType ().Name);
    MethodInfo method = t.GetMethod("get_answer");
    method.Invoke(t,new object[] { mov }));   <--- PROBLEM HERE
}
Run Code Online (Sandbox Code Playgroud)

始终存在与最后一行相关的"对象与目标类型不匹配"的错误.你有什么建议?

Jon*_*nna 9

method.Invoke(t,new object[] { mov }));
Run Code Online (Sandbox Code Playgroud)

和打电话一样

t.WhateverTheMethodIs(mov);
Run Code Online (Sandbox Code Playgroud)

tType,不是那种类型的对象.你需要传入对象来调用那里的方法.(如果方法是静态的,则为null).