private void OnTriggerExit2D(Collider2D other) { if (other.CompareTag("Player")) { this.targetPlayer = null; this.state = AIBattleState.IDLE; StopCoroutine(CheckSelfCondition()); StopCoroutine(ExecuteScript()); } }
IEnumerator CheckSelfCondition() { while (this.player != null) { int engageChance = UnityEngine.Random.Range(0, 100); if (engageChance < player.GetHP()) { this.state = AIBattleState.ENGAGE; } else { this.state = AIBattleState.AVOID; } yield return(new WaitForSeconds(0.2F)); } yield break; }
IEnumerator ExecuteScript() { while (this.state != AIBattleState.IDLE && targetPlayer != null) { if (this.state == AIBattleState.ENGAGE) { this.EngageTarget(); float reAimDelay = UnityEngine.Random.Range(aimDelay.x, aimDelay.y); yield return(new WaitForSeconds(reAimDelay)); } else if (this.state == AIBattleState.AVOID) { this.AvoidTarget(); yield return(new WaitForSeconds(0.2F)); } } if (targetPlayer == null) { this.state = AIBattleState.IDLE; } yield break; }