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; reduce.SpawnIfAvailable(position); Transform o = objectQueue.Dequeue(); o.localScale = scale; o.localPosition = position; nextPosition.x += scale.x; //select random materials for the platforms int materialIndex = Random.Range(0, materials.Length); o.renderer.material = materials[materialIndex]; o.collider.material = physicMaterials[materialIndex]; objectQueue.Enqueue(o); nextPosition += new Vector3( Random.Range(minGap.x, maxGap.x) + scale.x, Random.Range(minGap.y, maxGap.y), Random.Range(minGap.z, maxGap.z)); if (nextPosition.y < minY) { nextPosition.y = minY + maxGap.y; } else if (nextPosition.y > maxY) { nextPosition.y = maxY - maxGap.y; } }