void HighlightUnits(List <int> positions) { // Reset old highlight if (_mouseoverUnits.Count > 0) { for (int i = 0; i < _mouseoverUnits.Count; i++) { SpriteRenderer rend = _mouseoverUnits[i].GetComponentInChildren <SpriteRenderer>(); rend.color = Color.white; rend.transform.localScale = Vector2.one; _mouseoverUnits[i].SetUIFocus(false); } } // Find if there is a unit and highlight it _mouseoverUnits.Clear(); if (positions.Count > 0) { for (int i = 0; i < positions.Count; i++) { BaseUnit unit = _units[positions[i]]; if (unit) { _mouseoverUnits.Add(unit); } } // Check the target type against the unit for (int i = _mouseoverUnits.Count - 1; i >= 0; i--) { if (_mouseoverUnits[i].IsPlayer() && (_targetEntity == TargetEntity.Enemy || _targetEntity == TargetEntity.Hazard)) { _mouseoverUnits.RemoveAt(i); } else if (!_mouseoverUnits[i].IsPlayer() && (_targetEntity == TargetEntity.Player || _targetEntity == TargetEntity.Hazard)) { _mouseoverUnits.RemoveAt(i); } } // TEMP little highlight animation for (int i = 0; i < _mouseoverUnits.Count; i++) { BaseUnit unit = _mouseoverUnits[i]; SpriteRenderer rend = unit.GetComponentInChildren <SpriteRenderer>(); rend.color = Color.Lerp(Color.white, Color.red, 0.5f + 0.2f * Mathf.Sin(Time.time * 15f)); rend.transform.localScale = Vector2.one * (1.0f + 0.2f * Mathf.Sin(Time.time * 4f + 1)); _mouseoverUnits[i].SetUIFocus(true); } } else { } }
// Click on a unit in the list of units, and make the unit "selected" public void selectUnit() { // This if statement is required otherwise units and tile can be selected though the UI if (gameMap.gameManager.buttonSelectedFrame == false) { // if player turn... if (Input.GetMouseButtonDown(0)) { // Find the mouse position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // if raycast player collider set unit selected to be true if (Physics.Raycast(ray, out hit)) { BaseUnit baseUnit = hit.collider.GetComponent <BaseUnit>(); if (baseUnit != null) { GetComponent <LineRenderer>().positionCount = 0; // if it is player 1's turn and they select one of player 1's units, make unit slected = true if (gameMap.gameManager.playerTurn == 1) { if (baseUnit.unitType == BaseUnit.UnitTypes.King || baseUnit.unitType == BaseUnit.UnitTypes.Beaver || baseUnit.unitType == BaseUnit.UnitTypes.Elephant || baseUnit.unitType == BaseUnit.UnitTypes.Hawk) { selectedObject = baseUnit; gameMap.gameManager.updateHUD(); unitSelected = true; selectedObject.GetComponentInChildren <AudioSource>().Play(); } } // if it is player 2's turn and they select one of player 2's units, make unit slected = true else if (gameMap.gameManager.playerTurn == 2) { if (baseUnit.unitType == BaseUnit.UnitTypes.Monster) { selectedObject = baseUnit; unitSelected = true; selectedObject.GetComponentInChildren <AudioSource>().Play(); } } else { selectedObject = null; unitSelected = false; } } } } } }
override public void Activate(BaseUnit unit) { if (unit == null) { Debug.LogWarning("Invald Unit Input"); } unit.mana = unit.mana + 2; ManaBar mb = unit.GetComponentInChildren <ManaBar>(); mb.mana = unit.mana; this.isUsed = true; }
override public void Activate(BaseUnit unit) { if (unit == null) { Debug.LogWarning("Invald Unit Input"); } unit.health = unit.health + 2; HealthBar hb = unit.GetComponentInChildren <HealthBar>(); hb.health = unit.health; hb.max_health = hb.max_health + 2; this.isUsed = true; }