コード例 #1
0
    private IEnumerator Pattern1()
    {
        int   numberOfWavesLeft       = 10;
        int   numberOfBulletsPerWave  = 20;
        int   numberOfChargingBullets = 5;
        float waveArc        = 360;
        float secondsPerShot = 0.2f;

        while (numberOfWavesLeft > 0)
        {
            Vector3 spawnLocation = gameObject.transform.position + Vector3.up * (5 - 10 * Random.value);

            Vector3 Direction = player.transform.position - spawnLocation;
            for (int i = 0; i < numberOfBulletsPerWave; i++)
            {
                GameObject newShot = objectPool.GetEnemyBullet();
                newShot.transform.position = spawnLocation;
                var shotBehavior = newShot.GetComponent <BulletBehavior>();

                Vector3 newDirection = new Vector3(Direction.x * Mathf.Cos(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i))
                                                   + Direction.y * Mathf.Sin(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i)),
                                                   Direction.y * Mathf.Cos(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i))
                                                   - Direction.x * Mathf.Sin(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i)), Direction.z);


                if (shotBehavior != null)
                {
                    shotBehavior.SetBulletDestination(newDirection + spawnLocation);
                    shotBehavior.SetBulletSpeed(0.25f);
                }
            }

            for (int i = 0; i < numberOfChargingBullets; i++)
            {
                GameObject newShot = objectPool.GetEnemyBullet();
                newShot.transform.position = spawnLocation;
                var shotBehavior = newShot.GetComponent <BulletBehavior>();

                if (shotBehavior != null)
                {
                    shotBehavior.SetBulletDestination(player.transform.position);
                }
                yield return(new WaitForSeconds(secondsPerShot));
            }

            numberOfWavesLeft--;
        }
    }
コード例 #2
0
    private IEnumerator Pattern1(float waveArc)
    {
        int   numberOfWavesLeft      = 10;
        int   numberOfBulletsPerWave = 10 * Mathf.FloorToInt(waveArc / 180);
        float secondsPerShot         = 0.5f;

        while (numberOfWavesLeft > 0)
        {
            Vector3 Direction = player.transform.position - gameObject.transform.position;
            for (int i = 0; i < numberOfBulletsPerWave; i++)
            {
                GameObject newShot = objectPool.GetEnemyBullet();
                newShot.transform.position = gameObject.transform.position;
                var shotBehavior = newShot.GetComponent <BulletBehavior>();

                Vector3 newDirection;
                if (numberOfWavesLeft % 2 == 0)
                {
                    newDirection = new Vector3(Direction.x * Mathf.Cos(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i))
                                               + Direction.y * Mathf.Sin(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i)),
                                               Direction.y * Mathf.Cos(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i))
                                               - Direction.x * Mathf.Sin(Mathf.Deg2Rad * (-45 + waveArc / numberOfBulletsPerWave * i)), Direction.z);
                }
                else
                {
                    newDirection = new Vector3(Direction.x * Mathf.Cos(Mathf.Deg2Rad * (45 - waveArc / numberOfBulletsPerWave * i))
                                               + Direction.y * Mathf.Sin(Mathf.Deg2Rad * (45 - waveArc / numberOfBulletsPerWave * i)),
                                               Direction.y * Mathf.Cos(Mathf.Deg2Rad * (45 - waveArc / numberOfBulletsPerWave * i))
                                               - Direction.x * Mathf.Sin(Mathf.Deg2Rad * (45 - waveArc / numberOfBulletsPerWave * i)), Direction.z);
                }

                if (shotBehavior != null)
                {
                    shotBehavior.SetBulletDestination(newDirection + gameObject.transform.position);
                    shotBehavior.SetBulletSpeed(0.2f);
                }
            }

            yield return(new WaitForSeconds(secondsPerShot));

            numberOfWavesLeft--;
        }
    }
コード例 #3
0
    private IEnumerator Pattern2()
    {
        int   numberOfWaves          = 5;
        int   numberOfWavesLeft      = numberOfWaves;
        int   numberOfBulletsPerWave = 5;
        int   BulletWaveSize         = 5;
        float secondsPerShot         = 0.3f;

        while (numberOfWavesLeft > 0)
        {
            Vector3 Direction = player.transform.position - gameObject.transform.position;
            for (int j = 0; j < BulletWaveSize; j++)
            {
                for (int i = 0; i < numberOfBulletsPerWave; i++)
                {
                    GameObject newShot = objectPool.GetEnemyBullet();
                    newShot.transform.position = gameObject.transform.position;
                    var shotBehavior = newShot.GetComponent <BulletBehavior>();

                    Vector3 newDirection = new Vector3(Direction.x * Mathf.Cos(Mathf.Deg2Rad * (-(360 - 270 / numberOfWaves * (numberOfWaves - numberOfWavesLeft))
                                                                                                / numberOfBulletsPerWave * i)) + Direction.y * Mathf.Sin(Mathf.Deg2Rad *
                                                                                                                                                         (-(360 - 270 / numberOfWaves * (numberOfWaves - numberOfWavesLeft)) / numberOfBulletsPerWave * i)),
                                                       Direction.y * Mathf.Cos(Mathf.Deg2Rad * (-(360 - 270 / numberOfWaves * (numberOfWaves - numberOfWavesLeft))
                                                                                                / numberOfBulletsPerWave * i)) - Direction.x * Mathf.Sin(Mathf.Deg2Rad *
                                                                                                                                                         (-(360 - 270 / numberOfWaves * (numberOfWaves - numberOfWavesLeft)) / numberOfBulletsPerWave * i)), Direction.z);

                    if (shotBehavior != null)
                    {
                        shotBehavior.SetBulletDestination(newDirection + gameObject.transform.position);
                        shotBehavior.SetBulletSpeed(0.15f);
                    }
                }

                yield return(new WaitForSeconds(secondsPerShot));
            }

            yield return(new WaitForSeconds(secondsPerShot * 3));

            numberOfWavesLeft--;
        }
    }
コード例 #4
0
    private IEnumerator Shoot()
    {
        isCoolingDown = true;

        GameObject newShot = objectPool.GetEnemyBullet();

        newShot.transform.position = gameObject.transform.position;
        var shotBehavior = newShot.GetComponent <BulletBehavior>();

        if (shotBehavior != null)
        {
            shotBehavior.SetBulletDestination(player.transform.position);
        }

        yield return(new WaitForSeconds(secondsPerShot));

        isCoolingDown = false;
    }