I am trying to randomize the selection of 3 objects that get displayed on a computer, when running either code I am left with the dreaded “Object reference not set to an instance of an object.” the objects are most certainly being found as without the array the items instantiate fine, but with an array I receive this error.
I have tried both this…
void addSale()
{
count++;
dummyTimer = addTimer;
rand = Random.Range(0, adArray.Length);
GameObject temp = Instantiate(adArray[rand], sales.transform);
}
and this…
void addSale()
{
count++;
dummyTimer = addTimer;
GameObject temp = Instantiate(adArray[Random.Range(0, adArray.Length)], sales.transform);
}
and this…
void addSale()
{
count++;
dummyTimer = addTimer;
int arrayLength = adArray.Length;
rand = Random.Range(0, arrayLength);
GameObject temp = Instantiate(adArray[rand], sales.transform);
}
With exact results…
Again. these objects Instantiate fine without an array… meaning that unity can find these objects without fail… untill I add the array, thats when unity can no longer reference the object that is trying to be instantiated, also the count is being added and the timer reset upon receiving the error.