- Home /
Decrease size of grid with prefabs?
I am working on making my grid using prefabs able to become smaller. I am running into some code errors. The grid does appear, but when I try and make it smaller by pressing the "Decrease Size" Button I get an Argument Exception error: The Object you want to instantiate is null.
Here is the grid class
public class MapGrid : MonoBehaviour {
public Transform tilePrefab;
private int sizeX = 2;
private int sizeY = 2;
void Start(){
generateGrid ();
}
public void generateGrid(){
for (int varX = 0; varX < getSizeX(); varX++) {
for (int varY = 0; varY < getSizeY(); varY++) {
//how to get it so that they populate
Instantiate (tilePrefab,new Vector3(500+varX*270,500+varY*270,-5), Quaternion.Euler(270,0,0));
}
}
}
public int setSizeX(int varX)
{
sizeX = varX;
return sizeX;
}
public int getSizeX(){
return sizeX;
}
public int setSizeY(int varY)
{
sizeY = varY;
return sizeY;
}
public int getSizeY(){
return sizeY;
}
}
Here is the decrease size class
public class DecreaseSize : MonoBehaviour {
//allows access to public mapgrid fuctions
MapGrid mg = new MapGrid();
int x;
int y;
public DecreaseSize(){
x = mg.getSizeX();
y = mg.getSizeY ();
}
void Start () {
decreaseMapSize ();
}
public void decreaseMapSize(){
mg.setSizeX (x-1);
mg.setSizeY (y -1);
mg.generateGrid ();
}
}
My thought process is that when I press the decrease size button I will have decreased the size of the grid by 1 on both the x, and y axis. Then I call the function again to repopulate the grid. Not sure what to do from here. Thanks!
Your answer
Follow this Question
Related Questions
Trying to make a grid! 0 Answers
Scale the standard Transform Handle 2 Answers
Create a grid on a cube? 0 Answers
Need more buttons to this script. 1 Answer
Increase height of panel w/ gridlayout when new objects added 1 Answer