コード例 #1
0
    //Spawn a random asteroid in a random direction
    void Spawn()
    {
        //Generate random index into asteroid pieces array
        int randomIndex = Random.Range(0, asteroidPieces.Length);

        //Select random asteroid piece
        GameObject astroidPiece = asteroidPieces[randomIndex];

        //Ask the Asteroid Manager to spawn a new asteroid piece at a position
        AsteroidManager.Spawn(astroidPiece, transform.position);
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: kennetha123/Asteroid
    private void Update()
    {
        spawnRate           = defaultSpawnRate + ((float)currentScore / 100000f);
        asteroidMaxInstance = defaultAsteroidMaxInstance + ((int)currentScore / 5000);

        if (spawnTime > 0 && asteroidCounter < asteroidMaxInstance)
        {
            spawnTime -= Time.deltaTime;

            if (spawnTime <= 0)
            {
                int pos = Random.Range(0, spawnPointTotal);
                asteroidCounter++;

                try
                {
                    asteroidManager.Spawn(pos);
                }
                catch
                {
                    int type = Random.Range(0, asteroidPrefab.Length);
                    asteroidManager.Create(type, pos);
                }

                // reset timer
                spawnTime = 1f / spawnRate;
            }
        }
        else
        {
            spawnTime = 1f / spawnRate;
        }

        if (currentScore >= 5000)
        {
            if (ufoSpawnTime > 0 && ufoCounter < maxUFOInstance)
            {
                ufoSpawnTime -= Time.deltaTime;

                if (ufoSpawnTime <= 0)
                {
                    CreateUFO();

                    ufoSpawnTime = 20;
                }
            }
            else
            {
                ufoSpawnTime = 20;
            }
        }
    }