private void UpdateTarget() { _targets = ProximityProvider.GetPlayersPosition(); foreach (var target in _targets) { if (Vector3.Distance(gameObject.transform.position, target.transform.position) <= AggroDistance) { //Debug.Log("Target aquired"); _agent.SetDestination(target.transform.position); _lockedTarget = target; _gettingIntoRange = true; return; } } // todo: change to castle; if (Vector3.Distance(_agent.destination, _house) >= 4) { //Debug.Log("Changig destination from " + _agent.destination); if (!_agent.isOnNavMesh) { return; } _agent.SetDestination(_house); _agent.speed = _defaultAgentSpeed; _gettingIntoRange = false; // CancelInvoke("AttackTarget"); } }
private void Start() { if (PollingInterval <= 0) { PollingInterval = 1; } _animation = GetComponent <Animation>(); if (_animation) { foreach (AnimationState o in _animation) { if (o.name.ToLower().Contains("attack")) { _attackState = o; break; } } } _timeStamp = Time.time; _targets = ProximityProvider.GetPlayersPosition(); _agent = GetComponent <NavMeshAgent>(); _defaultAgentSpeed = _agent.speed; _attackSpeed = GetComponent <Enemy>().AttackSpeed; InvokeRepeating("UpdateTarget", 1, PollingInterval); }