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

前端 未结 1 515
一个人的身影
一个人的身影 2020-12-20 15:52

I\'m trying to call a method using a string, but there a problem:

void make_moviment(string mov,Vector3 new_mov){
    GameObject past_panel = GameObject.Find         


        
相关标签:
1条回答
  • 2020-12-20 16:47
    method.Invoke(t,new object[] { mov }));
    

    Is the same as calling

    t.WhateverTheMethodIs(mov);
    

    But t is the Type, not the object of that type. You need to pass in the object to call the method on there instead. (Or null if the method is static).

    0 讨论(0)
提交回复
热议问题