Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // Generate new tubes and delete old
        int tubes = tubesObject.transform.childCount;

        if (tubes == 0)
        {
            Tube.CreateTubes(character.gameObject.transform.position.x + tubeInitOffset, 10);
        }
        else
        {
            Transform firstTube = tubesObject.transform.GetChild(0);

            if (!Camera.main.IsObjectVisible(Tube.GetBasicGameObject(firstTube.gameObject)))
            {
                Destroy(firstTube.gameObject);
            }

            Transform lastTube = tubesObject.transform.GetChild(tubes - 1);
            if (Camera.main.IsObjectVisible(Tube.GetBasicGameObject(lastTube.gameObject)))
            {
                GameObject newTube = Tube.CreateTubes(tubesObject.transform.GetChild(tubes - 1).transform.position.x + tubeOffset, Random.Range(tubeMinHeight, tubeMaxHeight));
            }
        }

        if (!character.isPlaying)
        {
            return;
        }
        foreach (Transform tube in tubesObject.transform)
        {
            tube.transform.position -= new Vector3(speed, 0, 0) * Time.deltaTime;
        }
    }
Ejemplo n.º 2
0
    // Create first tubes before first frame
    void initTubes()
    {
        if (tubesObject.transform.childCount == 0)
        {
            throw new System.ArgumentException("Initial Tube not found, you have to create first tube in editor.");
        }

        Transform firstTube = tubesObject.transform.GetChild(0);

        while (Camera.main.IsObjectVisible(Tube.GetBasicGameObject(firstTube.gameObject)))
        {
            Tube.CreateTubes(firstTube.position.x + tubeOffset, Random.Range(tubeMinHeight, tubeMaxHeight));
            firstTube = tubesObject.transform.GetChild(tubesObject.transform.childCount - 1);
        }
    }