i´ve been working on a game in Unity and created a gamefield consisting of Transform objects. Now i wanted to integrate a simulation of the game,which is not running on the actuall gamefield, but on a clone of the gamefield which is not visible for the player ( this is needed for a AI algorithm im working on). Unitl now this is what i´ve got to clone the gamefield:
public Transform[,] vertricalArray;
public Transform[,] horizontalArray;
public Transform[,] boxes;
public Transform[,] sim_Box;
public Transform[,] sim_Vertical;
public Transform[,] sim_Horizontal;
for (int y = 0; y <= 3; y++) {
for (int x = 0; x <= 3; x++)
{
if (x != 3 && y != 3)
sim_Box[x, y] = Instantiate(boxes[x,y], transform.position, transform.rotation) as Transform;
if (y != 3)
sim_Vertical[x, y] = Instantiate(vertricalArray[x,y], transform.position, transform.rotation) as Transform;
if (x != 3)
sim_Horizontal[x, y] = Instantiate(horizontalArray[x,y], transform.position, transform.rotation) as Transform;
}
}
this is supposed to clone the objects from the gamefield (verticalArray etc.) into the simulation gamefield (sim_Vertical etc.) Whenever i try to start this though, i get the error, that the sim_ arrays are null and i can´t copy those objects into the sim_ arrays. Would appreciate help and also if someone knows a better way to create a gamefield for the simulation im very open for ideas!
Thanks!