Ejemplo n.º 1
0
    void Update()
    {
        // jumping
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Mouse0))
        {
            if (grounded)
            {
                groundPos     = transform.position;
                movingUpwards = true;
                playerAnim.SetBool("Jump", true);
            }
        }

        if (movingUpwards && curMovingUpTime > 0)
        {
            curMovingUpTime -= Time.deltaTime;
        }
        else if (movingUpwards)
        {
            curMovingUpTime = movingUpTime;
            movingUpwards   = false;
        }
        if (movingUpwards)
        {
            transform.Translate(Vector3.up * jumpSpeed * Time.smoothDeltaTime);
        }
        else if (!movingUpwards && !grounded)
        {
            transform.Translate(Vector3.down * fallSpeed * Time.smoothDeltaTime);
            //if (transform.position.y < groundPos.y)
        }
        if (grounded)
        {
            //transform.position = groundPos;
            playerAnim.SetBool("Jump", false);
        }
        // move left
        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            bgScript.SetSpeed(leftSpeed);
        }
        else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            bgScript.SetSpeed(rightSpeed);
        }
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow))
        {
            bgScript.SetSpeed(defaultSpeed);
        }
        else if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow))
        {
            bgScript.SetSpeed(defaultSpeed);
        }


        // move right
    }
Ejemplo n.º 2
0
    void Update()
    {
        // jumping
        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Mouse0)) && !bgScript.IsPaused())
        {
            if (grounded)
            {
                groundPos     = transform.position;
                movingUpwards = true;
                grounded      = false;
                jump.Play();
            }
        }

        if (movingUpwards && curMovingUpTime > 0)
        {
            curMovingUpTime -= Time.deltaTime;
        }
        else if (movingUpwards)
        {
            curMovingUpTime = movingUpTime;
            movingUpwards   = false;
        }
        if (movingUpwards)
        {
            transform.Translate(Vector3.up * jumpSpeed * Time.smoothDeltaTime);
        }
        else if (!movingUpwards && !grounded)
        {
            transform.Translate(Vector3.down * fallSpeed * Time.smoothDeltaTime);
            //if (transform.position.y < groundPos.y)
        }
        // move left
        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            bgScript.SetSpeed(leftSpeed);
        }
        else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            bgScript.SetSpeed(rightSpeed);
        }
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow))
        {
            bgScript.SetSpeed(defaultSpeed);
        }
        else if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow))
        {
            bgScript.SetSpeed(defaultSpeed);
        }


        // check for falling
        if (transform.position.y <= -3f)
        {
            PlayerDie();
        }
    }