//Click on Mech void MouseOver_Mech(GameObject ourHitObject) { if (Input.GetButtonDown("Fire1")) { //select the mech you click on if (ourHitObject.GetComponent <MechStats>()) { selectedMech = ourHitObject.GetComponent <MechStats>(); } else if (ourHitObject.GetComponent <WeaponStats>()) { selectedMech = ourHitObject.GetComponentInParent <MechStats>(); } Debug.Log(selectedMech.mech.name + " Selected. " + selectedMech.mech.hpTorso + " Torso HP remaining."); } }
//Click on Hex void MouseOver_Hex(GameObject ourHitObject) { if (Input.GetButtonDown("Fire1")) { //select the Hex you click on selectedHex = ourHitObject.GetComponentInChildren <Hex>(); // Debug.Log(selectedHex.name); //move the selected mech if (selectedMech != null && selectedMech.mech.movementRemaining >= selectedMech.mech.movementCostPerHex) { //set the starting node for pathfinding start = selectedMech.transform.localPosition; //change the parent of the selected mech to the newly clicked hex selectedMech.transform.parent = selectedHex.transform; //set the end point for pathfinding end = selectedMech.transform.localPosition; //call the moveUnit method for the selectedMech and pass it the pathfinding coords selectedMech.moveUnit(start, end); //deselect the mech selectedMech = null; } } }
IEnumerator selection() { selectedMechLast = selectedMech; selectedMech = null; Debug.Log("Select Mech To Attack"); yield return(new WaitUntil(() => selectedMech != null || Input.GetKey(KeyCode.Escape))); //cancel if escape if (Input.GetKey(KeyCode.Escape)) { selectedMech = selectedMechLast; Debug.Log("Attack Canceled"); yield break; } //if a new mech is selected, attack it else if (selectedMech != null && selectedMech != selectedMechLast) { //spend the TP required to attack with the selected weapon selectedMechLast.spendTP(selectedWeapon.weapon.tpCost); //call the weapon's method of attack, passing it the attacked mech selectedWeapon.atkMech(selectedMech); //reselect original mech selectedMech = selectedMechLast; shots--; selectedWeapon.shotsRemaining = shots; // Debug.Log(shots); if (shots > 0) { yield return(StartCoroutine(selection())); } else { selectedWeapon.rdyToFire = false; yield break; } } }
//include the mech to be attacked as an argument public void atkMech(MechStats mech) { //call the damage method and pass it the weapon's damage stat mech.takeDamage(weapon.damage, weapon.weaponName); }