public override void Start() { target = GetTarget(); firePeriodically = FirePeriodically(); StartCoroutine(firePeriodically); }
IEnumerator FirePeriodically() { while (true) { if (!targetIsAlive) { _target = GetTarget(); if (_target != null) { targetIsAlive = true; } } var offset = Random.Range(minFireDelayOffset, maxFireDelayOffset); yield return(new WaitForSeconds(offset)); MessageBus.FireBullet.Invoke(); yield return(new WaitForSeconds(fireDelay - offset)); } }
void TargetDestroyed(BaseBehaviour destroyed) { targetIsAlive = false; }