// Use this for initialization void Awake() { //get level data var lvlPL = GameObject.FindGameObjectWithTag("LevelPlaylist").GetComponent <LevelPlaylist>(); var lvlDB = GameObject.FindGameObjectWithTag("EntityDatabase").GetComponent <LevelDatabase>(); stats = lvlDB.getLevel(lvlPL.getCurrentLevelName()); //var spawn_positions=new List<Tile>(); mesh_bounds = tile_mesh.renderer.bounds; main_camera = GameObject.Find("Main Camera").GetComponent <CameraScript>(); main_camera.DetachPlane(); var hexa_size = mesh_bounds.size; terrain = new Tile[LevelWidth, LevelHeight]; var pos = Vector3.zero; float tile_w = hexa_size.x, tile_h = hexa_size.z; //ground_prefab.transform.localScale.x //creating tiles Vector3 coor = new Vector3(0, 0, 0); for (int i = 0; i < terrain.GetLength(0); i++) { if (i % 2 != 0) { pos.z = tile_h / 2; } else { pos.z = 0; } if (i != 0 && (i % 2 == 0)) { coor.x -= 1; } coor.y = i; for (int j = 0; j < terrain.GetLength(1); j++) { var tile = Instantiate(ground_prefab, pos, Quaternion.identity) as Transform; tile.transform.parent = transform; var ts = tile.GetComponent("Tile") as Tile; terrain[i, j] = ts; tiles.Add(ts); ts.setCoordinate(new Vector3(coor.x + j, coor.y, -((coor.x + j) + coor.y))); if (Subs.RandomPercent() < stats.Tile_random_low_change) { ts.Tile_Data.setMovementBounds(stats.Tile_random_low_height, 0f); ts.Tile_Data.setTimeBounds(stats.Tile_random_time_min, stats.Tile_random_time_max, true); } if (Subs.RandomPercent() < stats.Tile_random_high_change) { ts.Tile_Data.setMovementBounds(stats.Tile_random_high_height, 0f); ts.Tile_Data.setTimeBounds(stats.Tile_random_time_min, stats.Tile_random_time_max, true); } pos.z += tile_h + 0.01f; } //pos.x+=tile_w+(tile_w*0.5f); pos.x += tile_w * (3f / 4f); } //load land shape DEV. circle int xx = terrain.GetLength(0) / 2, yy = terrain.GetLength(1) / 2; center_point = terrain[xx, yy].getCoordinate(); var radius = xx - 1; for (int i = 0; i < terrain.GetLength(0); i++) { for (int j = 0; j < terrain.GetLength(1); j++) { var ts = terrain[i, j]; if (!HexaDistanceInside(center_point, ts.getCoordinate(), radius)) { ts.gameObject.SetActive(false); } } } //group up tiles int group_amount = radius + 1; for (int g = 0; g < group_amount; g++) { radius = (group_amount - g); var data = new TileData(Vector3.zero, g); data.setMovementBounds(0.03f, 0.03f); data.setTimeBounds(1000, 1000, true); tile_groups.Add(data); foreach (var ts in tiles) { if (HexaDistanceInside(center_point, ts.getCoordinate(), radius)) { ts.setTileGroup(data); } } } terrain[xx, yy].setTileGroup(null); //center not moving terrain[xx, yy].Tile_Data.Activate(false); main_camera.setMiddlePos(terrain[xx, yy].transform.position); terrain_timer = new Timer(stats.Terrain_deterioration_time, OnTerrainTrigger); //main_camera.transform.position=new Vector3(terrain[xx,yy].transform.position.x,main_camera.transform.position.y,main_camera.transform.position.z); //main_camera.LookAtCenter(terrain[xx,yy].transform.position); main_camera.DetachPlane(); //pause level Activate(false); foreach (var t in tile_groups) { t.Activate(false); } }