// Update is called once per frame
    void Update()
    {
        paused = player.GetComponent <Move>().isPaused();

        //Move the platforms if the game is not paused
        if (paused == false)
        {
            platformCounter = player.GetComponent <Move>().getPlatformCounter();

            //Changes the speed of the platforms based on the players score
            if (platformCounter > 40)
            {
                platformSpeed = .15f;
            }
            else if (platformCounter > 20 && platformCounter < 40)
            {
                platformSpeed = 0.1f;
            }
            else if (platformCounter < 1)
            {
                platformSpeed = 0.01f;
            }

            //Creates a platform
            if (!platCreated)
            {
                floor         = GameObject.Find("Floor");
                platGen       = floor.GetComponent <PlatformGenerator>();
                platCreated   = platGen.getPlatformsDone();
                moveDirection = Random.RandomRange(0, 2);
            }

            //when the platform is created it starts moving left or right based in the number assigned to it
            if (platCreated)
            {
                if (moveDirection == 0)
                {
                    transform.position = new Vector2(transform.position.x - platformSpeed, transform.position.y);

                    if (transform.position.x - transform.localScale.x / 2 < -11)
                    {
                        moveDirection = 1;
                    }
                }
                else
                {
                    transform.position = new Vector2(transform.position.x + platformSpeed, transform.position.y);

                    if (transform.position.x + transform.localScale.x / 2 > 11)
                    {
                        moveDirection = 0;
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //If you clicked the playbutton
        if (camera.transform.rotation.y > 0 && camera.transform.rotation.y < 0.1)
        {
            follow         = camera.GetComponent <FollowPlayer>();
            follow.enabled = true;

            paused = player.GetComponent <Move>().isPaused();

            if (paused == false)
            {
                //TimeLeft1 is a large timer that lets the player have a head start
                timeLeft1 -= Time.deltaTime;

                //once that time is up the second timer gets activated and its a lot faster
                if (timeLeft1 < 0)
                {
                    firstTimer = true;
                }


                if (!platsCreated)
                {
                    platsCreated = platGen.getPlatformsDone();
                }

                if (platsCreated)
                {
                    if (firstTimer)
                    {
                        timeLeft2 -= Time.deltaTime;

                        //if the time is up the first child platform is removed from the container.
                        if (timeLeft2 < 0 && platformCounter != 0)
                        {
                            //Debug.Log("TIMERS UP");
                            Destroy(platParent.transform.GetChild(0).gameObject);
                            timeLeft2 = 1f;
                            platformCounter--;
                        }
                    }
                }
            }
        }
    }