2d array isn't declared even though I declared it
I have this code right here which creates a 2d array which is initialized after the class and monobehavior (I don't remember this part name)
[SerializeField] public int[,] priceManager;
I initialized the array in a method within Start() method this way:
public void Method1()
{
priceManager[product.id, 0] = product.price1;
priceManager[product.id, 1] = product.price2;
priceManager[product.id, 2] = product.price3;
priceManager[product.id, 3] = product.price4;
priceManager[product.id, 4] = product.price5;
}
The 'product' items are suppose to return integers. I have checked them and they are all correct. However I try to access this data from another method but the method doesn't recognize the array after filling in the values in the first method.
public void Method2()
{
Debug.Log(priceMangaer[1,0]);
}
Thus gives me this error:
NullReferenceException: Object reference not set to an instance of an object
I can't see what's wrong and I am stuck on it. What went wrong?
$$anonymous$$ethod1
does not initializes the array. It fills it. I don't think the method even work. You should have a NullReferenceException
too.
Initializing the array should look like this:
price$$anonymous$$anager = new int[width, height];
well, it solved it :) but I want to make it dynamic so I could draw external values, how can it be done?