public IEnumerator StartStage() { if (_shooter != null) { UBulletPoolManager poolManager = _shooter.GetBulletPoolManager(); // Check if the bulletIndex is in valid range (bullet exists) if (_bulletIndex >= 0 && _bulletIndex < poolManager.GetPrototypesCount()) { for (int i = 0; i < _count; i++) { UBulletObject fetchedBullet = poolManager.FetchBulletByID(_bulletIndex, true, _shouldBulletAddToMonitor, _shouldBulletActivateCollider); // rotate fetched bullet to have the same rotation as the shooter. // This is meaningful as we want bullets to shoot at the same UP direction of the shooter Transform fetchedBulletTrans = fetchedBullet.GetTransform(); Transform shooterTrans = _shooter.GetTransform(); fetchedBulletTrans.position = shooterTrans.position; fetchedBulletTrans.rotation = shooterTrans.rotation; // More motion settings on the bullet itself _bulletInitEvent.Invoke(fetchedBullet); // Invoke shootEvent here _shooter.GetActor().InvokeShootEvents(fetchedBullet); // all non-last shots should wait for the specified interval if (i < _count - 1) { yield return(new WaitForSeconds(_intervalFunc())); } } } } _isComplete = true; yield break; }
public UShootActor InvokeShootEvents(UBulletObject shotBullet) // This will be called in StartStage() in stages immediately on shoot { if (shootEvents != null) { shootEvents.Invoke(shotBullet); } return(this); }
public IEnumerator StartStage() { if (_shooter != null) { UBulletPoolManager poolManager = _shooter.GetBulletPoolManager(); // Check if the bulletIndex is in valid range (bullet exists) if (_bulletIndex >= 0 && _bulletIndex < poolManager.GetPrototypesCount()) { // Forever and infinite while (true) { // when this is true, the infinite call is forcefully stopped if (_isForceStopped) { break; } UBulletObject fetchedBullet = poolManager.FetchBulletByID(_bulletIndex, true, _shouldBulletAddToMonitor, _shouldBulletActivateCollider); // rotate fetched bullet to have the same rotation as the shooter. // This is meaningful as we want bullets to shoot at the same UP direction of the shooter Transform fetchedBulletTrans = fetchedBullet.GetTransform(); Transform shooterTrans = _shooter.GetTransform(); fetchedBulletTrans.position = shooterTrans.position; fetchedBulletTrans.rotation = shooterTrans.rotation; // More motion settings on the bullet itself _bulletInitEvent.Invoke(fetchedBullet); // Invoke shootEvent here _shooter.GetActor().InvokeShootEvents(fetchedBullet); yield return(new WaitForSeconds(_intervalFunc())); } } } yield break; }