Esempio n. 1
0
    void Update()
    {
        if (transform.position.x < generatePoint.position.x)
        {
            distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax);

            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) < randomCollectablePicker)
            {
                theCollectableGenerator.spawnCollectables(new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z));
            }

            if (Random.Range(0f, 100f) < randomTrapPicker)
            {
                GameObject newTrap = theTrapPools.GetPooledObject();

                float trapXPosition = Random.Range(-platformWidths[platformSelector] / 2 + 1f, platformWidths[platformSelector] / 2 - 1f);

                Vector3 trapPosition = new Vector3(trapXPosition, 0.7f, -1f);

                newTrap.transform.position = transform.position + trapPosition;
                newTrap.transform.rotation = transform.rotation;
                newTrap.SetActive(true);
            }

            transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2), transform.position.y, transform.position.z);
        }
    }
    public void spawnCollectables(Vector3 startPosition)
    {
        GameObject collectable1 = collectablePooler.GetPooledObject();

        collectable1.transform.position = startPosition;
        collectable1.SetActive(true);

        /*GameObject collectable2 = collectablePooler.GetPooledObject();
         * collectable2.transform.position = new Vector3(startPosition.x - distanceBetweenCollectables, startPosition.y, startPosition.z);
         * collectable2.SetActive(true);*/

        /*GameObject collectable3 = collectablePooler.GetPooledObject();
         * collectable3.transform.position = new Vector3(startPosition.x + distanceBetweenCollectables, startPosition.y, startPosition.z);
         * collectable3.SetActive(true);*/
    }