private void OnEnable() { //find player if player == null if (_player == null) { _player = FindObjectOfType <Player>(); } _source = GetComponent <AudioSource>(); if (_base == null) { _base = GameObject.FindGameObjectWithTag("Base"); } _agent = GetComponent <NavMeshAgent>(); _agent.speed = _movementSpeed; //depends on _isWaveEnemy if (_isWaveEnemy == false) { SetState(PatrolState.GetInstance()); } else { SetState(ChargeBaseState.GetInstance()); } }
public static ChargeBaseState GetInstance() { if (_instance == null) { _instance = new ChargeBaseState(); } return(_instance); }
public override void Update(EnemyAgent agent) { //update position of the player agent.SetPlayerTarget(); if (Vector3.Distance(agent.GetNavMeshAgent().destination, agent.transform.position) < agent.GetAttackRange() + 0.5f) { agent.SetState(AttackState.GetInstance()); } if (Vector3.Distance(agent.GetNavMeshAgent().destination, agent.transform.position) > agent.GetFollowRange() + 0.5f) { if (agent.GetIsWaveEnemy() == false) { agent.SetState(PatrolState.GetInstance()); } else { agent.SetState(ChargeBaseState.GetInstance()); } } }