小编Ber*_*hau的帖子

在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
}
Run Code Online (Sandbox Code Playgroud)

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

c# string reflection methods invoke

3
推荐指数
1
解决办法
5608
查看次数

标签 统计

c# ×1

invoke ×1

methods ×1

reflection ×1

string ×1