プログラミング初心者です。至らない点があればすみません。
目的:文字列を指定し、MethodInfoを使って呼び出したい
参考:https://nekosuko.jp/1895/
下記のエラーが出て、メソッドが呼び出されません。
NullReferenceException: Object reference not set to an instance of an object
sample01.Start () (at Assets/MyScripts/Sample/sample01.cs:17)
コード↓
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System; 5using System.Reflection; 6public class sample01 : MonoBehaviour 7{ 8 void Method() 9 { 10 Debug.Log("Method is calld."); 11 } 12 13 void Start() 14 { 15 Type type = this.GetType(); 16 MethodInfo method = type.GetMethod("Method"); 17 method.Invoke(this, null); 18 } 19}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。