// Update is called once per frame void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (GetComponent <Collider>().Raycast(ray, out hitInfo, Mathf.Infinity)) { x = (int)(hitInfo.point.x / _tileMap.tile_size); z = (int)(hitInfo.point.z / _tileMap.tile_size); //Debug.Log ("Tile: " + x + ", " + z); currentTileCoord.x = x + 0.5f; currentTileCoord.z = z + 0.5f; currentTileCoord.y = 0.001f; currentTileCoord.y = grid.getElevation(x, z) * 0.25f; selectionCube.transform.position = currentTileCoord * 1f; } else { // Hide selection cube? } if (Input.GetMouseButtonDown(0)) { } }
void Update() { if (once) { map.setTile(tileX, tileZ, false); once = false; } if (currentPath != null) { map.setTile(tileX, tileZ, true); } // Have we moved our visible piece close enough to the target tile that we can // advance to the next step in our pathfinding? if (Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(map.TileCoordToWorldCoord(tileX, tileZ).x, map.TileCoordToWorldCoord(tileX, tileZ).z)) < 0.1f) { AdvancePathing(); } // Smoothly animate towards the correct map tile. if ((float)decimal.Round((decimal)transform.position.y, 3) < map.getElevation(tileX, tileZ) * 0.25f) { elevate(); } if ((float)decimal.Round((decimal)transform.position.y, 3) > map.getElevation(tileX, tileZ) * 0.25f) { dElevate(); } if ((float)decimal.Round((decimal)transform.position.z, 2) > map.TileCoordToWorldCoord(tileX, tileZ).z) { moveDown(); } if ((float)decimal.Round((decimal)transform.position.z, 2) < map.TileCoordToWorldCoord(tileX, tileZ).z) { moveUp(); } if ((float)decimal.Round((decimal)transform.position.x, 2) > map.TileCoordToWorldCoord(tileX, tileZ).x) { moveLeft(); } if ((float)decimal.Round((decimal)transform.position.x, 2) < map.TileCoordToWorldCoord(tileX, tileZ).x) { moveRight(); } }