public void TrySelect() { if (hovoredTile != null && hovoredTile.IsPassable() && currentPlayer.ControlsTile(hovoredTile)) { if (hovoredTile.Equals(selectedTile)) { //Deselect if clicking on a selected tile selectedTile.Deselect(); selectedTile = null; hovoredTile.Highlight(highlightTile); } else { //Deselect old tile if (selectedTile != null) { selectedTile.Deselect(); selectedTile = null; } //Select new tile selectedTile = hovoredTile; selectedTile.Select(selectTile); } } }
public bool TryMove() { if (CanMove() && hovoredTile.army == null) { hovoredTile.army = selectedTile.army; selectedTile.army = null; selectedTile.Deselect(); selectedTile = hovoredTile; selectedTile.Select(selectTile); return(true); } return(false); }
void RaycastTiles() { RaycastHit tileHit; Ray screenRay = myCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(screenRay, out tileHit)) { if (tileHit.collider.CompareTag("Tile")) { WorldTile newTile = tileHit.collider.GetComponentInParent <WorldTile>(); if (newTile != selected) { if (selected != null) { selected.Deselect(); } selected = newTile; selected.Select(); } if (Input.GetMouseButtonDown(0)) //Change this to use virtual buttons later { if (lastClicked != null) { try { lastClicked.UnClick(); } catch { } } lastClicked = selected; selected.Click(); } } else { ClearSelection(); } } else { ClearSelection(); } }
//This makes the selected army "push" the losing army post-battle //TODO: can push onto an empty enemy tile public void Push() { List <Vector2Int> pushDirections = HexUtils.GetPushDirections(selectedTile.OffsetCoords, hovoredTile.OffsetCoords); foreach (Vector2Int pushDirection in pushDirections) { WorldTile pushTile; if (tiles.TryGetValue(new Vector3Int(hovoredTile.LocalPlace.x + pushDirection.x, hovoredTile.LocalPlace.y + pushDirection.y, hovoredTile.LocalPlace.z), out pushTile)) { if (pushTile.IsPassable() && pushTile.army == null) { pushTile.army = hovoredTile.army; hovoredTile.army = selectedTile.army; selectedTile.army = null; selectedTile.Deselect(); selectedTile = hovoredTile; selectedTile.Select(selectTile); break; } } } }