void DefensiveAction() { if (EnemyTarget == null) { Nodes Temp = null; for (int x = 0; x < GridRef.GetRows(); ++x) { for (int z = 0; z < GridRef.GetColumn(); ++z) { if (GridRef.GetNode(x, z).GetOccupied() != null && GridRef.GetNode(x, z).GetOccupied().tag == "PlayerUnit") { if (Temp != null) // Temp Magnitude is more than current grid magnitude, change Temp altogether { if ((Temp.GetOccupied().transform.position - currNode.transform.position).magnitude > (GridRef.GetNode(x, z).GetOccupied().transform.position - currNode.transform.position).magnitude) { Temp = GridRef.GetNode(x, z); } } else // Sets the first reference of Temp { Temp = GridRef.GetNode(x, z); } } } } EnemyTarget = Temp; } else { if (!Path_Set) { SetDefensivePath(currNode, EnemyTarget); m_path.Dequeue(); Path_Set = true; } else { if (!isAttacking) { // Assigns a node while also removing the assigned node from the path Nodes TempMove = currNode; if (m_path.Count != 0) { TempMove = m_path.Dequeue(); } else { turnManager.CalculateRestHeal(this.gameObject); } // If the next area is or isn't the enemy target, act accordingly if (TempMove != EnemyTarget) { currNode.SetOccupiedNULL(); currNode = TempMove; currNode.SetOccupied(this.gameObject); } else { isAttacking = true; TempMove.SetSelectable(false); int damageDeal = turnManager.CalculateDamage(this.gameObject, EnemyTarget.GetOccupied()); EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().HP -= damageDeal; if (EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().HP <= 0) { EnemyTarget = null; } } } else { // prevent error - if player died if (EnemyTarget.GetOccupied() == null) { EnemyTarget = null; return; } UnitVariables Temp = EnemyTarget.GetOccupied().GetComponent <Players> ().GetStats(); int damageDeal = turnManager.CalculateDamage(this.gameObject, EnemyTarget.GetOccupied()); Temp.HP -= damageDeal; EnemyTarget.GetOccupied().GetComponent <Players> ().SetStats(Temp); EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().UpdateHealthBar(); EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().UpdateUnitInfo(); if (EnemyTarget.GetOccupied().GetComponent <UnitVariables> ().HP <= 0) { EnemyTarget = null; } } this.Stats.AP--; } } }