我想从另一个脚本更改数组数据。
public class Shop : MonoBehaviour {
public int[] Available; // 0 or 1 for each element // contain 12 elements
...
}
public class Class2 : MonoBehaviour {
public void Func() {
// Option 1 //
Shop _Shop = (Shop)GameObject.FindObjectOfType (typeof(Shop));
_Shop.Available [0] = 1;
}
...
// Option 2 //
this.GetComponent<Shop> ().Available [0] = 1;
}
...
}
还是做了一个数组public static int []可用;并将其更改为Shop.Available [0] = 1;
所有示例都给出相同的错误:对象引用未设置为对象的实例