// Update is called once per frame
    void Update()
    {
        if (transform.position.x < generationPoint.position.x)
        {
            // Generating Upper platforms
            if (Random.Range(0f, 100f) < upPlatformThreshold)
            {
                distanceBetween  = Random.Range(distanceBetweenMin, distanceBetweenMax);
                platformSelector = Random.Range(0, theObjectPools.Length);

                heightChange = transform.position.y + Random.Range(maxHeightChange, -maxHeightChange);

                if (heightChange > maxHeight)
                {
                    heightChange = maxHeight;
                }

                if (heightChange < minHeight)
                {
                    heightChange = minHeight;
                }

                float finalHeightChange = 0.0f;
                while ((Physics2D.OverlapArea(new Vector2(transform.position.x + distanceBetween - 0.5f, heightChange + finalHeightChange + 0.5f), new Vector2(transform.position.x + platformWidths[platformSelector] + 0.5f, heightChange + finalHeightChange - 0.5f))))
                {
                    finalHeightChange += 0.5f;
                }
                transform.position = new Vector3(transform.position.x + (platformWidths [platformSelector] / 2) + distanceBetween, heightChange + finalHeightChange, transform.position.z);

                GameObject newPlatform = theObjectPools [platformSelector].GetPooledObject();
                newPlatform.transform.position = transform.position;
                newPlatform.transform.rotation = transform.rotation;
                newPlatform.SetActive(true);

                if ((Random.Range(1, 100) < 15) && (heightChange + finalHeightChange >= maxHeight))
                {
                    theCoinGenerator.SpawnHeart(new Vector3(transform.position.x + (platformWidths[platformSelector] / 2) + 4f, transform.position.y + 1.5f, transform.position.z));
                }


                // Select which game object to spawn on ground
                switch (Random.Range(2, 3))
                {
                // Enemy kill box
                case 1:
                    theEnemyGenerator.spawnEnemy(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z), false);
                    break;

                // Coins
                case 2:
                    float coinCountNumber = Random.Range(2, 5);
                    // if(!(Physics2D.OverlapArea(new Vector2(transform.position.x + distanceBetween - 0.5f, heightChange + finalHeightChange + 0.5f), new Vector2(transform.position.x + platformWidths[platformSelector]+0.5f, heightChange +finalHeightChange - 0.5f))))
                    // theCoinGenerator.SpawnCoins (coinCountNumber, new Vector3 (transform.position.x, transform.position.y + 1.0f, transform.position.z));
                    break;

                // Obstacles
                case 3:
                    theObstacleGenerator.spawnObstacle(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z));
                    break;
                }

                // New Platform position
                transform.position = new Vector3(transform.position.x + Random.Range(2f, 30f), transform.position.y, transform.position.z);
            }
        }
    }