Exemplo n.º 1
0
    /*
     * public void CannotJumpBecauseInAir () {
     *      if (!myEnabledAbilitiesScript.getCanDoubleJump ()) {
     *              canJump = false;
     *      }
     * }
     */

    // Update is called once per frame
    void Update()
    {
        if (isPlayerVelocitySet)
        {
            controlOfPlayerCountdown -= Time.deltaTime;
            if (controlOfPlayerCountdown <= 0)
            {
                isPlayerVelocitySet = false;
            }
        }

        float yVelocity = myRigidbody.velocity.y;
        float xVelocity = Input.GetAxis("Horizontal") * playerspeed;

        if (xVelocity > 0)
        {
            myDirectionScript.SetFacingRight();
        }
        else if (xVelocity < 0)
        {
            myDirectionScript.SetFacingLeft();
        }

        if (isPlayerVelocitySet)
        {
            myRigidbody.velocity = controlledVelocity;
        }
        else
        {
            myRigidbody.velocity = new Vector3(xVelocity, yVelocity, 0);
        }

        if ((Input.GetButtonDown("Jump")) && (canJump))
        {
            Jump();
        }

        if (singleJumpCountdown >= 0f)
        {
            singleJumpCountdown -= Time.deltaTime;
        }

        //Set sound for footsteps
        if (grounded && ((Input.GetAxis("Horizontal") <= -.2) || (Input.GetAxis("Horizontal") >= .2)))
        {
            if (!footstepsSoundSource.isPlaying)
            {
                footstepsSoundSource.Play();
            }
        }
        else
        {
            if (footstepsSoundSource.isPlaying)
            {
                footstepsSoundSource.Stop();
            }
        }
    }