From f5e4c8b789128bcc48fcd2e9b340e6728df80cf0 Mon Sep 17 00:00:00 2001 From: j-weissen Date: Thu, 23 Jun 2022 14:41:14 +0200 Subject: [PATCH] Tiles now in 2D list --- Assets/Scripts/TileController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/TileController.cs b/Assets/Scripts/TileController.cs index 18dfb7b..c8b55c0 100644 --- a/Assets/Scripts/TileController.cs +++ b/Assets/Scripts/TileController.cs @@ -1,26 +1,30 @@ using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Tilemaps; public class TileController : MonoBehaviour { public GameObject tile; public GameObject cameraGameObject; - public List Tiles; + public List> Tiles; // Start is called before the first frame update void Start() { Camera camera = cameraGameObject.GetComponent(); + Tiles = new List>(); Vector3 screen = camera.ViewportToWorldPoint(new Vector3(1, 1, camera.nearClipPlane)); int x = Convert.ToInt32(Math.Ceiling(screen.x)); int y = Convert.ToInt32(Math.Ceiling(screen.y)); for(int xx = -x; xx <= x; xx++) { + List temp = new List(); for(int yy = -y; yy <= y; yy++) { if(tile != null) { - Tiles.Add(Instantiate(tile, new Vector3(xx, yy, 0), Quaternion.identity)); + temp.Add(Instantiate(tile, new Vector3(xx, yy, 0), Quaternion.identity)); } } + Tiles.Add(temp); } } } \ No newline at end of file