void Update() { switch (_currentStatus) { case SentryBotStatus.Idling: gameObject.GetComponent <SpriteRenderer>().sprite = frontFacing; direction = PlayerController.Direction.Stationary; if (CanSeePlayer()) { _currentStatus = SentryBotStatus.AttackingPlayer; } else { DoIdleBob(); } break; case SentryBotStatus.AttackingPlayer: if (CanSeePlayer()) { // face player if (_player.transform.position.x < transform.position.x) { // player is left of bot gameObject.GetComponent <SpriteRenderer>().sprite = leftFacing; direction = PlayerController.Direction.Left; } else { // consider player is right of bot gameObject.GetComponent <SpriteRenderer>().sprite = rightFacing; direction = PlayerController.Direction.Right; } SetLaunchpointOnDirection(); FireBullet(); } else { gameObject.GetComponent <SpriteRenderer>().sprite = frontFacing; direction = initialDirection; _currentStatus = initialStatus; } break; case SentryBotStatus.Hunting: DoPatrol(); if (CanSeePlayer()) { _currentStatus = SentryBotStatus.AttackingPlayer; } break; } }
private void Awake() { startPosition = transform.position; initialStatus = _currentStatus; initialDirection = direction; _currentDestination = _startWaypoint; if (_player == null) { _player = GameObject.Find("Player").GetComponent <PlayerController>(); } SetLaunchpointOnDirection(); _lastShotFired = 0f; _health = _startingHealth; AudioSource[] sounds = transform.GetComponentsInChildren <AudioSource>(); _gunshot_sound = sounds[0]; _explosion_sound = sounds[1]; }