示例#1
0
 // Update is called once per frame
 void Update()
 {
     if (StaticLevelState.getState() == 0)
     {
         menu.SetActive(true);
         gameOverMenu.SetActive(false);
         scoresPanel.SetActive(false);
         for (int i = 0; i < UI.Count; i++)
         {
             UI [i].SetActive(false);
         }
     }
     else if (StaticLevelState.getState() == 1)
     {
         menu.SetActive(false);
         gameOverMenu.SetActive(false);
         scoresPanel.SetActive(false);
         for (int i = 0; i < UI.Count; i++)
         {
             UI [i].SetActive(true);
         }
     }
     else if (StaticLevelState.getState() == 2)
     {
         menu.SetActive(false);
         gameOverMenu.SetActive(true);
         scoresPanel.SetActive(false);
         for (int i = 0; i < UI.Count; i++)
         {
             UI [i].SetActive(true);
         }
     }
     else
     {
         menu.SetActive(false);
         gameOverMenu.SetActive(false);
         for (int i = 0; i < UI.Count; i++)
         {
             UI [i].SetActive(false);
         }
     }
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (lastPositionBackground.x < GameController.instance.player.transform.position.x + backgroundHorizontalLength / 2 - 10)
        {
            rotateBackgroundQueuePlataform();
        }

        if (lastPositionFirstFloor.x < GameController.instance.player.transform.position.x + firstFloorgroundHorizontalLenght * numPlataformsInAdvance)
        {
            rotateFirstQueuePlataform();
        }

        if (lastPositionSecondFloor.x < GameController.instance.player.transform.position.x + secondFloorgroundHorizontalLenght * numPlataformsInAdvance)
        {
            rotateSecondQueuePlataform();
        }

        destroyObjects();

        if (StaticLevelState.getState() == 1)
        {
            if (!GameController.instance.player.isPlayerDead())
            {
                timerLeftToSpwan -= Time.deltaTime;
                timerTimeToInc   -= Time.deltaTime;
                if (timerLeftToSpwan <= 0f)
                {
                    creatObjects();
                }
                if (timerTimeToInc <= 0f && smallerTimeToSpawn > minTimeToSpawn)
                {
                    timerTimeToInc = Random.Range(downTimeToIncreaseSpawn, topTimeToIncreaseSpawn);
                    float smallerTime = smallerTimeToSpawn - Random.Range(0.2f, 0.6f);
                    smallerTimeToSpawn = smallerTime > minTimeToSpawn ? smallerTime : minTimeToSpawn;
                    biggestTimeToSpawn = smallerTimeToSpawn + 0.5f;

                    //Debug.Log("decrease time to spawn " + smallerTimeToSpawn + " -> " + biggestTimeToSpawn);
                }
            }
        }
    }
示例#3
0
    // Update is called once per
    void Update()
    {
        if (!isDead)
        {
            if (haveColideWithOtherStudent)
            {
                timerLeftSlowDown -= Time.deltaTime;
                if (timerLeftSlowDown < 0)
                {
                    haveColideWithOtherStudent = false;
                }
            }

            // secondFloor colider is importante to make the double jump to the secound floor only
            isGrounded = Physics2D.IsTouchingLayers(playerColider, firstFloor);              //|| Physics2D.IsTouchingLayers(playerColider, otherObject);
            if (isGrounded)
            {
                doubleJump = false;
            }
            setPlayerHorizontalSpeed(!haveColideWithOtherStudent ? playerCurrentSpeed : (playerCurrentSpeed / 2.0f));
            if (StaticLevelState.getState() == 1)
            {
                if (Input.GetMouseButtonDown(0) && !haveColideWithOtherStudent)
                {
                    if (isGrounded)
                    {
                        playerRgBody.velocity = new Vector2(playerRgBody.velocity.x, jumpSpeed);
                        SoundController.instance.playEffect(effect.jump);
                    }
                    else if (!doubleJump)
                    {
                        playerRgBody.velocity = new Vector2(playerRgBody.velocity.x, jumpSpeed);
                        SoundController.instance.playEffect(effect.jump);
                        doubleJump = true;
                    }
                }

                // gui update
                timePlayed += Time.deltaTime;

                meters         += (playerCurrentSpeed * Time.deltaTime) / 2f;
                metersText.text = meters.ToString("0.00 ") + "m";

                // speed up level
                timerLeftToIncrease -= Time.deltaTime;
                if (timerLeftToIncrease <= 0f && playerCurrentSpeed < playerMaxSpeed)
                {
                    timerLeftToIncrease = Random.Range(downTimeToIncreaseSpeed, topTimeToIncreaseSpeed);
                    float speed = playerCurrentSpeed + Random.Range(1.0f, 2f);
                    playerCurrentSpeed = speed < playerMaxSpeed ? speed : playerMaxSpeed;
                    //Debug.Log("acelarate " + playerCurrentSpeed);
                }


                // jump animation
                anim.SetFloat("jump", playerRgBody.velocity.y);


                if (Health <= 0)
                {
                    killPlayer();
                }
            }
        }

        if (haveColideWithOtherStudent)
        {
            cantJump.SetActive(true);
        }
        else
        {
            cantJump.SetActive(false);
        }

        if (isOnSecondFloor())
        {
            boost.SetActive(true);
        }
        else
        {
            boost.SetActive(false);
        }
    }