Ejemplo n.º 1
0
    private void Recycle()
    {
        Vector3 scale = new Vector3(
            Random.Range(minSize.x, maxSize.x),
            Random.Range(minSize.y, maxSize.y),
            Random.Range(minSize.z, maxSize.z));


        Vector3 position = nextPosition;

        position.x += scale.x * 0.5f;
        position.y += scale.y * 0.5f;

        coins.SpawnIfAvailable(position);
        coin2.SpawnIfAvailable(position);
        coin3.SpawnIfAvailable(position);
        coin4.SpawnIfAvailable(position);
        coin5.SpawnIfAvailable(position);

        spikeTrap.SpawnIfAvailable(position);
        spikeTrap2.SpawnIfAvailable(position);
        spikeTrap3.SpawnIfAvailable(position);

        speedUp.SpawnIfAvailable(position);
        speedUp2.SpawnIfAvailable(position);
        speedUp3.SpawnIfAvailable(position);

        speedDown.SpawnIfAvailable(position);
        speedDown2.SpawnIfAvailable(position);
        speedDown3.SpawnIfAvailable(position);

        inverse.SpawnIfAvailable(position);
        inverse2.SpawnIfAvailable(position);


        Transform o = objectQueue.Dequeue();

        o.localScale    = scale;
        o.localPosition = position;
        int materialIndex = Random.Range(0, materials.Length);

        o.GetComponent <Renderer>().material = materials[materialIndex];
        objectQueue.Enqueue(o);

        nextPosition += new Vector3(
            Random.Range(minGap.x, maxGap.x) + scale.x,
            Random.Range(minGap.y, maxGap.y),
            Random.Range(0, 0));

        if (nextPosition.y < minY)
        {
            nextPosition.y = minY + maxGap.y;
        }
        else if (nextPosition.y > maxY)
        {
            nextPosition.y = maxY - maxGap.y;
        }
    }