The important bit is the construction of the reference using a string. ie, I need to get access to that int[] from the construction of a string.
For example using "myClass ["int"+myString]" to access myClass.intArray
What am I doing wrong? How can I do this?
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class MyClass : MonoBehaviour {
public int[] intArray = new int[3]{1,2,3};
}
//---------------------------------------------------------------------------
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
public class MyOtherClass : MonoBehaviour {
MyClass myClass;
void theMethod(string myString){
myClass = GetComponent<MyClass> ();
//-->Error is here://
int[] theArray = myClass.GetType ().GetFields (myClass ["int"+myString]);
//--//
theArray[0] = 4;
}
void Awake(){ theMethod("Array"); }
}
Aucun commentaire:
Enregistrer un commentaire