private void AffixToGrid() { // Find the position that the Grid thinks our current position in the world // should equate to, and assign the waypoint to that new grid position. // This makes sure that, if the user is trying to move the cube in the world // to a spot that would equate to a new Grid position, that the new Grid position // will actually be stored successfully for this cube. Vector2Int newGridPosition = HullGridAdapter.GetGridPosition( this.transform.localPosition.x, this.transform.localPosition.z); // Now that the grid position is updated, reset our position in the world // to match whatever the Grid thinks it should be. This "Snaps" the in-world Cube // to the grid's alignment, making sure it can't be placed in an illegal "partway" point // in the world, or be rotated illegally. Vector2 worldCoords = HullGridAdapter.GetWorldPosition(newGridPosition); this.transform.localPosition = new Vector3(worldCoords.x, 0.0f, worldCoords.y); this.transform.localRotation = Quaternion.identity; _lastKnownPosition = newGridPosition; UpdateLabel(); }
private void Start() { _lastKnownPosition = HullGridAdapter.GetGridPosition(this.transform.position.x, this.transform.position.z); }