Exemplo n.º 1
0
    void Update()
    {
        if (Input.GetKeyDown(JumpKey) && canJump == true)
        {
            Debug.Log("Jumped");
//			body.velocity = Vector2.up * jumpForce;
            jumpSound.PlayOneShot(jumpClip);
            body.velocity = new Vector2(body.velocity.x, jumpForce);
            if (body.velocity.y <= 0)
            {
                body.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
            }
            else if
            (body.velocity.y > 0 && !Input.GetKey(JumpKey))
            {
                body.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
            }

//			body.velocity = constantSpeed * (body.velocity.normalized);
//			body.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
            canJump = false;
//			jump = true;
        }

        if (Input.GetKeyDown(PauseKey))
        {
            Debug.Log("Paused");
        }

        if (Input.GetKeyDown(InteractKey))
        {
            if (grabable)
            {
                if (!grabbed)
                {
                    Debug.Log("I grabbed something!");
                    pickUpScript.SetParent(this.gameObject);
                    grabbed = true;
                }
            }
        }

        if (Input.GetKeyUp(InteractKey))
        {
            Debug.Log("I let something go!");
            pickUpScript.DetachFromParent();
            grabbed = false;
        }

        if (Input.GetKeyDown(ThrowKey))
        {
            Debug.Log("Tossed!");
        }
    }