private void InitializeTile(TileType type, int x, int y) { string resourceName; switch (type) { case TileType.GROUND: resourceName = "ground"; break; case TileType.SOLID_WALL: resourceName = "wall"; break; case TileType.BREAK_BLOCK: resourceName = "vase"; break; case TileType.BREAK_START: resourceName = "ground"; var breaker = Resources.Load("Actors/breaker"); breakerObj = Instantiate(breaker, BasePosition + new Vector3(tileLength * x - tileLength / 2f, 2.4f, tileLength * y - tileLength / 2f), Quaternion.identity) as GameObject; Breaker = breakerObj.GetComponent <Breaker>(); Breaker.Initialize(mapManager, new Position(x, y)); break; case TileType.FIX_BLOCK: resourceName = "crate_broken"; break; case TileType.FIX_START: resourceName = "ground"; var fixer = Resources.Load("Actors/fixer"); fixerObj = Instantiate(fixer, BasePosition + new Vector3(tileLength * x - tileLength / 2f, 2.4f, tileLength * y - tileLength / 2f), Quaternion.identity) as GameObject; Fixer = fixerObj.GetComponent <Fixer>(); Fixer.Initialize(mapManager, new Position(x, y)); break; case TileType.BOTH_ACT_BLOCK: resourceName = "crate"; break; case TileType.BUTTON: resourceName = "button"; break; case TileType.DOOR: resourceName = "door"; break; case TileType.HOLE: resourceName = "hole"; break; case TileType.BREAK_EXIT: resourceName = "break_exit"; break; case TileType.FIX_EXIT: resourceName = "fix_exit"; break; case TileType.EXIT_BOTH: resourceName = "exit_both"; break; default: return; } try { if (resourceName == "ground") { resourceName += rand.Next(1, 4); } var tileObject = Instantiate(Resources.Load(BasePath + resourceName), BasePosition + new Vector3(tileLength * x, 0, tileLength * y), Quaternion.identity); var tileReference = tileObject as GameObject; var tile = tileReference.GetComponent <Tile>(); tileMap[x, y] = tile; gameObjects.Add(tileReference); } catch (Exception ex) { Debug.LogError(ex.Message); var tileObject = Instantiate(Resources.Load(BasePath + "ground" + rand.Next(1, 5)), BasePosition + new Vector3(tileLength * x, 0, tileLength * y), Quaternion.identity); var tile = (tileObject as GameObject).GetComponent <Tile>(); tileMap[x, y] = tile; } }