// Start is called before the first frame update void Start() { _player = GameObject.FindGameObjectWithTag(Constants.TagPlayer).GetComponent <PlayerAttackable>(); _alive = true; if (Waypoints != null && Waypoints.Length > 0) { LookAtDestination(); StartCoroutine(Patrol()); } Status = EnemyAIStatus.Idle; SuspicionLevel = 0; }
public override void CheckStatus() { float magnitude = (this.player.get_position() - this.get_transform().get_position()).get_magnitude(); if (magnitude < this.attackDistance) { this.status = EnemyAIStatus.Attack; } else if (magnitude > this.attackDistance) { this.status = EnemyAIStatus.Idle; } }
public override void Update() { this.CheckStatus(); EnemyAIStatus enemyAIStatus = this.status; if (enemyAIStatus == EnemyAIStatus.Idle) { this.Idle(); } else if (enemyAIStatus == EnemyAIStatus.Attack) { this.Attack(); } }
IEnumerator GetSuspicious() { Status = EnemyAIStatus.Suspicious; if (SuspicionLevel <= 0) { SuspicionLevel = 1; } else if (SuspicionLevel == 100) { SuspicionLevel = 99; } SuspicionLevelFloat = SuspicionLevel; while (SuspicionLevel > 0 && SuspicionLevel < 100) { Animator.SetFloat("Speed", 0); if (PlayerInRange && CanPlayerBeSeen(out _)) { var distanceFromPlayer = Vector2.Distance(_player.transform.position, transform.position); SuspicionLevelFloat += SuspicionIncreaseRate / distanceFromPlayer; SuspicionLevel = (int)SuspicionLevelFloat; FacePlayer(); } else { SuspicionLevel -= SuspicionDecreaseRate; } yield return(new WaitForSeconds(0.1f)); } if (SuspicionLevel <= 0) { SuspicionLevel = 0; Status = EnemyAIStatus.Idle; } else if (SuspicionLevel >= 100) { GetComponent <AudioSource>().PlayOneShot(Ah); SuspicionLevel = 100; Status = EnemyAIStatus.Aiming; StartCoroutine(AimContinuouslyAtPlayer()); StartCoroutine(AimAndShootAtPlayer()); } }
IEnumerator AimContinuouslyAtPlayer() { // go to aiming status Status = EnemyAIStatus.Aiming; while (Status == EnemyAIStatus.Aiming) { if (PlayerInRange && CanPlayerBeSeen(out var whereToShoot)) { FacePlayer(); // aim at player Animator.SetFloat("Speed", 0); Animator.SetBool("IsAiming", true); Animator.SetFloat("AimAngle", AimAngleToBlendingAimAngle(whereToShoot.Value)); } yield return(new WaitForSeconds(0.1f)); } Animator.SetBool("IsAiming", false); }
IEnumerator AimAndShootAtPlayer() { // go to aiming status Status = EnemyAIStatus.Aiming; while (Status == EnemyAIStatus.Aiming) { // wait for a while yield return(new WaitForSeconds(AimTimeBeforeShoot)); if (CanPlayerBeSeen(out var whereToShoot)) { // if player is still castable, shoot it ShootAtPlayer(whereToShoot.Value); } else { // Can't see player anymore. Revert to suspicious StartCoroutine(GetSuspicious()); } } }
public EnemyBot() { this.attackDistance = 10f; this.fireRate = 1.4f; this.status = EnemyAIStatus.Idle; }