public void ProcessClick(Transform target) { if (gameStarted) { int currentUnitIndex = TerrainGenerator.Instance.FindTileIndex(teams[activePlayer].units[activeUnit].tileOwned); int targetIndex = 0; if (target.gameObject.name.Contains("Hex")) { targetIndex = TerrainGenerator.Instance.FindTileIndex(target); } else if (target.gameObject.name.Contains("Unit")) { Debug.Log("Clicked unit, finding owned tile instead."); targetIndex = TerrainGenerator.Instance.FindTileIndex(target.GetComponent <Unit>().tileOwned); } if (!EventSystem.current.IsPointerOverGameObject()) { if (teams[activePlayer].logicType == Team.Logic.Human) { switch (actionMode) { case (SelectedMode.Move): aimLine.enabled = false; if (target.gameObject.name.Contains("Hex") && target.GetComponent <HexUnit>().isAvailableForMovement) { teams[activePlayer].units[activeUnit].GetComponent <Unit>().MoveToTile(target); OnClearTilesSelection(); actionMode = SelectedMode.None; OnModeUpdated(); } else { ShowToast("Not Enough energy!"); } break; case (SelectedMode.Attack): OnClearTilesSelection(); if (teams[activePlayer].units[activeUnit].energyLeft >= attackCost) { Unit targetUnit = TerrainGenerator.Instance.hexes[targetIndex].GetComponent <HexUnit>().Owner; if (targetUnit != null) { Attack(targetUnit); } } else { ShowToast("Not Enough energy!"); } break; case (SelectedMode.Bomb): Debug.Log("Bomb!"); OnClearTilesSelection(); aimLine.enabled = false; if (teams[activePlayer].units[activeUnit].energyLeft >= bombCost) { if (TerrainGenerator.Instance.CalculatePathDistance(currentUnitIndex, targetIndex, 0) <= bombReach) { Transform epicenter = TerrainGenerator.Instance.hexes[targetIndex]; epicenter.GetComponent <HexUnit>().Rise(-0.05f); if (epicenter.GetComponent <HexUnit>().Owner != null) { epicenter.GetComponent <HexUnit>().Owner.ReceiveDamage(15); } foreach (Transform t in TerrainGenerator.Instance.GetHexNeighbours(epicenter)) { HexUnit hex = t.GetComponent <HexUnit>(); hex.Rise(UnityEngine.Random.Range(-0.03f, -0.02f)); if (hex.Owner != null) { hex.Owner.ReceiveDamage(15); } } Instantiate(explosionPrefab, new Vector3(0, 2, 0) + TerrainGenerator.Instance.hexes[targetIndex].position, Quaternion.identity); teams[activePlayer].units[activeUnit].energyLeft -= bombCost; } else { ShowToast("Too far!"); } } else { ShowToast("Not Enough energy!"); } break; case (SelectedMode.Rise): Debug.Log("Rise!"); OnClearTilesSelection(); aimLine.enabled = false; if (teams[activePlayer].units[activeUnit].energyLeft >= bombCost) { if (TerrainGenerator.Instance.CalculatePathDistance(currentUnitIndex, targetIndex, 0) <= riseReach) { Transform epicenter = TerrainGenerator.Instance.hexes[targetIndex]; epicenter.GetComponent <HexUnit>().Rise(0.05f); foreach (Transform t in TerrainGenerator.Instance.GetHexNeighbours(epicenter)) { t.GetComponent <HexUnit>().Rise(UnityEngine.Random.Range(0.03f, 0.02f)); } teams[activePlayer].units[activeUnit].energyLeft -= bombCost; } else { ShowToast("Too far!"); } } else { ShowToast("Not Enough energy!"); } break; default: break; } } //This player is controller by AI! else { } } OnUnitChange(false); } }