"Object does not match target type" 在 C# 中使用字符串调用方法时

"Object does not match target type" when calling methods using string in C#

我正在尝试使用字符串调用方法,但出现问题:

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
}

总有这个错误 "Object does not match target type" 与最后一行有关。你有什么建议?

method.Invoke(t,new object[] { mov }));

与调用相同

t.WhateverTheMethodIs(mov);

但是tType,不是那个类型的对象。您需要传入对象以调用那里的方法。 (如果方法是静态的,则为 null)。