// Update is called once per frame void Update() { switch (badGuyStates) { case BadGuyStates.Idle: if (BadGuy.LineToPlayer(eyeSight.position)) { badGuyStates = BadGuyStates.SeekingPlayer; lastPosition = transform.position; } break; case BadGuyStates.SeekingPlayer: if (Time.time - followTimer > followPrecision) { followTimer = Time.time; BadGuy.FollowPlayerShell(navMeshAgent, 3, Random.Range(0, 360)); } if (Time.time - fireRateTimer > fireRateTimer) { if (BadGuy.LineToPlayer(eyeSight.position, 10)) { navMeshAgent.isStopped = true; badGuyStates = BadGuyStates.ShotPlayer; coolTimer = Time.time; BadGuy.LaunchProjectile2D(prefab_projectile, eyeSight.position); fireRateTimer = Time.time; } } break; case BadGuyStates.ShotPlayer: if (Time.time - coolTimer < coolDown) { navMeshAgent.isStopped = false; navMeshAgent.SetDestination(lastPosition + Vector3.right * Random.Range(-3, 3)); } else { badGuyStates = BadGuyStates.Idle; } break; } }
// Update is called once per frame void Update() { switch (ghostStates) { case GhostStates.Idle: if (BadGuy.LineToPlayer(transform.position, 35f) && Time.time - timer > 4) { BadGuy.FollowPlayer(navMeshAgent); ghostStates = GhostStates.Charging; } break; case GhostStates.Charging: if (navMeshAgent.remainingDistance < 1) { timer = Time.time; ghostStates = GhostStates.Idle; } BadGuy.HitPlayer(transform.position, navMeshAgent.velocity.normalized); break; } }