IEnumerator MoveToStartingPoint(Vector3 startingPoint) { while ((startingPoint - transform.position).sqrMagnitude > 0.01f) { Vector3 direction = (startingPoint - transform.position).normalized; transform.position = transform.position + direction * _speed * Time.deltaTime; yield return(null); } _attackable.enabled = true; HelperAttackable.AddAttackable(_attackable); _state = State.Active; }
private void UpdateTarget() { // Check if current target is still valid if (_target != null) { if (!IsValidTarget(_target)) { _target = null; } } // Try to find a target if it doesn't have one if (_target == null) { Attackable nearestEnemy = HelperAttackable.FindNearestEnemy(_side, transform.position); if (nearestEnemy != null && IsValidTarget(nearestEnemy)) { Debug.Log("Found target!"); _target = nearestEnemy; } } }