private IEnumerator Shoot() { yield return(_shoot.Engage(_target)); if (!_target || !_target.Alive) { GameManager.Instance.Produce(_structure.Production); ResourceCounter.Instance.Send(transform.position, _structure.Production.Keys); } _target = null; }
private void Update() { var newTarget = Physics .OverlapSphere(transform.position, _shoot.Range) .Select(c => c.GetComponent <Enemy>()) .FirstOrDefault(c => c != null); if (newTarget == _target) { return; } if (_shooting != null) { StopCoroutine(_shooting); } _target = newTarget; _shooting = StartCoroutine(Shoot()); }