Example #1
0
    public void Spawn(float startY, float endY)
    {
        List <GameObject> fruitsToPass = new List <GameObject>();

        // Dont spawn fruit at the start of the bg
        float lastY = startY + 1f;

        endY -= 1f;

        while (true)
        {
            if (lastY > endY)
            {
                break;
            }

            float x;

            if (_creatingCombo)
            {
                x = Random.Range(-0.8f, 0.8f);
            }
            else
            {
                x = _spawnedCount % 2 == 0 ? Random.Range(0.8f, maxX) : Random.Range(minX, -0.8f);
            }

            Vector3    temp        = new Vector3(x, lastY, 0f);
            GameObject fruitPrefab = GetFruit();

            GameObject fruit = Instantiate(fruitPrefab, Vector3.zero, Quaternion.identity);
            fruit.transform.parent   = transform;
            fruit.transform.position = temp;
            lastY += Random.Range(minYThreshold, maxYThreshold);
            _spawnedCount++;
            fruitsToPass.Add(fruit);
        }

        enemiesSpawner.Spawn(fruitsToPass);
    }