- Home /
How do I create a grid system like the game BBTan
I am trying to create a grid system for an android game using sprites similarly to BBtan. Can someone please help i have look and researched everywhere and can't create one.
Answer by ShadyProductions · May 29, 2017 at 07:45 AM
You can make an array which can resemble a grid.
Say you have an object called tile with all its properties and methods.
public class Tile {
public int value; //value of the tile
}
then you can make a multidimensional array that can resemble your grid. Like follows:
int xSize = 10;
int ySize = 7;
Tile[,] grid = new Tile[xSize, ySize];
you can then loop over each index and assign a tile to it.
for (int x=0; x < xSize; x++) {
for (int y=0; y < ySize; y++) {
Tile tile = new Tile();
tile.value = x + y; //give it a random value that adds up
grid[x,y] = tile;
}
}
Now you only need to render the grid, you can do this by using Instantiate on prefab cubes with a texture on it for example and place them according to the x and y position in the array, or if you have a very big map you will have to use meshes. But I think you could pull it off with instantiate if you have a small map.
Something like:
public Transform obj;
for (int x=0; x < xSize; x++) {
for (int y=0; y < ySize; y++) {
//where obj is your prefab that has a texture on it for example
Instantiate(obj, new Vector3(x, y, 0), Quaternion.identity);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612122949im_/https://answers.unity.com/themes/thub/images/avi.jpg)