コード例 #1
0
    IEnumerator NewWave()
    {
        //После задержки waveSpawnTime берёт из пула и расставляет большие астероиды
        yield return(new WaitForSeconds(waveSpawnTime));

        for (int i = 0; i < currentAsteroidsCountAtWave; i++)
        {
            GameObject newAsteroid = objectsPool.GetPooledObject(ObjectsPool.PoolType.bigAsteroid);

            float   screenRatio = (float)Screen.width / Screen.height;
            Vector3 direction   = new Vector3(Random.Range(-mainCamera.orthographicSize, mainCamera.orthographicSize)
                                              * screenRatio, 0, Random.Range(-mainCamera.orthographicSize, mainCamera.orthographicSize));

            newAsteroid.transform.LookAt(direction);

            newAsteroid.GetComponent <Asteroid>().Activate(GetAsteroidSpawnPosition(), this, Random.Range(minAsteroidSpeed, maxAsteroidSpeed));
        }

        //Расширение пула астероидов
        currentAsteroidsCountAtWave += increaseAsteroidsCount;
        objectsPool.PoolsExtension();
    }