0

I want to change array data from another script.

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;
    }
    ...
}

or did an array public static int[] Available; and change it Shop.Available[0] = 1;

All examples give the same error: Object reference not set to an instance of an object

0 Answers0