public void GenerateMap() { TileGenerator tileGenerator = new TileGenerator(WaterPrefab, GrassPrefab, DesertPrefab, MountainPrefab, ForestPrefab); Transform[,] tileTransforms = tileGenerator.GenerateTiles(); tiles = new Tile[tileTransforms.GetLength(0), tileTransforms.GetLength(1)]; // destroy/create container object Transform mapHolder = RestoreMapholder(); // create the tiles for (int x = 0; x < Constants.MapSettings.MapSize.X; x++) { for (int y = 0; y < Constants.MapSettings.MapSize.Y; y++) { Vector3 tilePosition = TileUtil.CoordToPosition(x, y); Transform newTile = Instantiate(tileTransforms[x, y], tilePosition, Quaternion.Euler(Vector3.right * 90)) as Transform; newTile.localScale = Vector3.one * Constants.MapSettings.TileSize; newTile.Rotate(Vector3.back * GenerateDegree()); newTile.parent = mapHolder; newTile.name = "X:" + x + " Y:" + y + " " + newTile.tag; // store created tile for later access tiles[x, y] = newTile.GetComponent <Tile>(); // set properties of tile tiles[x, y].Type = GetType(tileTransforms[x, y]); tiles[x, y].Position = new Coord(x, y); } } }
public void SetUnit(MovableObject unit) { // actually set the position of the unit unit.transform.position = TileUtil.CoordToPosition(Position); // set a link to this tile in the unit unit.Tile = this; // store the building on this tile this.unit = unit; }
public void SetBuilding(SelectableObject building) { // actually set the position of the building building.transform.position = TileUtil.CoordToPosition(Position); // set a link to this tile in the building building.Tile = this; // store the building on this tile this.building = building; }
protected void Update() { if (move) { Vector3 target = TileUtil.CoordToPosition(targetTile.Position); transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * Speed); if (Vector3.Distance(transform.position, target) < 0.001f) { move = false; Tile.RemoveUnit(); targetTile.SetUnit(this); } } }