Hi,
i wanted to create a 2D array of GameObject (prefab). I want help for it. I tried, but doesn’t work.
The following is my code:
public GameObject tile;
for(int i=0; i<20; i++)
{
for(int j=0; j<20;j++)
{
floors[i,j]=(GameObject)Instantiate(tile, new Vector3((i*foradd)-begin, 10,(j*foradd)-begin),Quaternion.identity) ;
}
}
Thanks!
What type is the var “floors”?
Better, where you create?
How about declaring the variable before randomly using and hoping it works?
Thank you for reply
public GameObject[,] floors;
public GameObject[,] floors = new GameObject[20,20];
I did it, but it report error"A null value was found where an object instance was required."
floors=new GameObject[20,20];
for(int i=0; i<20; i++)
{
floors[i]= new GameObject[i];
for(int j=0; j<20;j++)
{
floors[i,j]=(GameObject)Instantiate(tile, new Vector3((i*foradd)-begin, 10,(j*foradd)-begin),Quaternion.identity) ;
}
Tseng
November 2, 2011, 12:07am
8
What’s the point of “floors_= new GameObject*;”, you already initialized did this with floors=new GameObject[20,20];*_
The Problem you get is probably because you haven’t assigned “tile” in the Inspector
Hi Thank you for reply. I assigned them~~