Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.x < generationPoint.position.x)
        {
            distanceBetween  = Random.Range(distanceMin, distanceMax);
            platformSelector = Random.Range(0, theObjectPools.Length);

            heightChange = transform.position.y + Random.Range(-maxHeightChange, maxHeightChange);
            if (heightChange > maxHeight)
            {
                heightChange = maxHeight;
            }

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

            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2) + distanceBetween,
                                             heightChange, transform.position.z);

            //Instantiate(thePlatforms[platformSelector], transform.position, transform.rotation);
            GameObject newPlatform = theObjectPools[platformSelector].GetPooledObject();

            newPlatform.transform.position = transform.position;
            newPlatform.transform.rotation = transform.rotation;
            newPlatform.SetActive(true);

            if (Random.Range(0f, 100f) < randomCoinThreshold)
            {
                theCoin.spawn(new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z));
            }

            if (Random.Range(randomCoinThreshold, 100f) < randomEnemyThreshold)
            {
                GameObject newEnemy = enemyPool.GetPooledObject();
                newEnemy.transform.position = new Vector3(transform.position.x + Random.Range(-(platformWidths[platformSelector] / 2), (platformWidths[platformSelector] / 2)), transform.position.y + 1f, transform.position.z);
                newEnemy.transform.rotation = transform.rotation;
                newEnemy.SetActive(true);
            }

            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2) + distanceBetween,
                                             transform.position.y, transform.position.z);
        }
    }