Пример #1
0
    void Recycle()
    {
        //determine randomly whether to place a gap
        bool  isGap   = false;
        float gapSize = 0;

        if (lastWasGap)
        {
            lastWasGap = false;
        }
        else
        {
            isGap = UnityEngine.Random.Range(0, 5) == 0 ? true : false;
            //randomly determine gap size
            if (isGap)
            {
                float speedModifier = (float)Math.Floor(runnerScript.GetSpeedUpCount());
                gapSize    = UnityEngine.Random.Range(minGap * speedModifier, maxGap * speedModifier);
                lastWasGap = true;
            }
        }
        //determine spawn location for next piece based on gap
        Vector3 pos = nextPos;

        pos.x += (surfaceWidth * gapSize);
        //dequeue surface leaving the screen and move it
        Transform newSurface = objectQueue.Dequeue();

        newSurface.localPosition = pos;
        nextPos.x = pos.x + surfaceWidth;
        //enqueue the surface at the end
        objectQueue.Enqueue(newSurface);
    }