Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Create an obstacles inside the map

$
0
0
Hai, i already create a map like this: ![alt text][1] [1]: /storage/temp/18336-map.png 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> map = new List>(); public int mapSize = 20; void GenerateMap() { map = new List>(); for (int i = 0; i < mapSize; i++) { List row = new List(); 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.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

Viewing all articles
Browse latest Browse all 171066


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>