Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
    IEnumerator ShootCoroutine()
    {
        bool isEven = true;

        while (true)
        {
            UBulletObject bulletObject;
            if (isEven)
            {
                bulletObject = poolManager.FetchBulletByID(0, true);
            }
            else
            {
                bulletObject = poolManager.FetchBulletByID(1, true);
            }

            isEven = !isEven;

            bulletObject.trans.position = shooter.transform.position;

            bulletObject.GetActor().AddDefaultCallback(() => {
                bulletObject.GetSpriteRenderer().color = Color.white;
            });
            bulletObject.GetActor().AddCollisionCallback(() => {
                bulletObject.GetSpriteRenderer().color = Color.red;
            });
            bulletObject.GetActor().AddBoundaryCallback(() => {
                bulletObject.trans.DOKill();
                bulletObject.Recycle();
            });

            Vector3 randVec = Random.insideUnitCircle;
            randVec.Scale(new Vector3(8f, 8f, 0f));
            bulletObject.GetTransform().DOMove(randVec, 5f);

            yield return(new WaitForSeconds(0.05f));
        }
    }
Ejemplo n.º 3
0
        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;
        }