- Home /
Question by
AxHaM · Jul 12, 2016 at 05:35 PM ·
instantiateprefabarray
Problem with instantiating prefab object
I don't know where the problem is: i wanted to instantiate a (random number)x(random number) platform using arrays and a prefab of a brick tile. Don't show any other solutions to achieve this goal, i just want a solution for this.
Error: NullReferenceException: Object reference not set to an instance of an object general_Script.posX () (at Assets/Scripts/general_Script.cs:49) general_Script.Start () (at Assets/Scripts/general_Script.cs:21)
public int dunNum;
public int dunNumSqrt;
private float[,] dunPosx;
private float[,] dunPosy;
public int dunDim;
public float tileDim = 0.16f;
public GameObject go;
void Start () {
dunNum = (int)Mathf.Pow(Random.Range(1,5),2);
dunNumSqrt = (int)Mathf.Sqrt(dunNum);
float[,] dunPosx = new float[dunNumSqrt,dunNumSqrt];
float[,] dunPosy = new float[dunNumSqrt,dunNumSqrt];
posX();
posY();
instantiateTile();
}
void Update () {}
void posX()
{
for (int i = 0;i < dunNumSqrt;i++)
{
for (int j = 0;j < i;j++)
{
dunPosx[i,j] = 0.16f*j;
}
}
}
void posY()
{
for (int i = 0;i < dunNumSqrt;i++)
{
for (int j = 0;j < i;j++)
{
dunPosy[i,j] = 0.16f*i;
}
}
}
void instantiateTile()
{
for(int i = 1;i < dunNumSqrt;i++)
{
for(int j = 1;j < dunNumSqrt;j++)
{
Instantiate(go,new Vector3(dunPosx[i,j],dunPosy[i,j],0),Quaternion.identity);
}
}
} }
Comment