Hai, i already create a map like this:
Now i want to draw a obstacles within those grids, how do i do that?
Right now i only be able to draw a obstacles during mouse down, but i am not able to generate a map that have a obstacles once i run the game.
Please help me.
Here is my code for making a grid in unity3d (c#):
public GameObject TilePrefab;
public List<List<Tile>> map = new List<List<Tile>>();
public int mapSize = 20;
void GenerateMap()
{
map = new List<List<Tile>>();
for (int i = 0; i < mapSize; i++)
{
List <Tile> row = new List<Tile>();
for (int j = 0; j < mapSize; j++)
{
Tile tile = ((GameObject)Instantiate(TilePrefab, new Vector3(i - Mathf.Floor(mapSize / 2), 0, -j + Mathf.Floor(mapSize / 2)), Quaternion.Euler(new Vector3()))).GetComponent<Tile>();
tile.gridPosition = new Vector2(i, j);
row.Add(tile);
}
map.Add(row);
}
}
And here is my code for draw a obstacles once i hit the mouse button (OnMouseDown):
public bool obstacles = false;
void OnMouseDown()
{
obstacles = obstacles ? false : true;
if (obstacles)
{
transform.renderer.material.color = new Color(.5f, .5f, 0.0f);
}
else
{
transform.renderer.material.color = Color.white;
}
}
Thank you very much! I appreciate your answer
