示例#1
0
    //FixedUpdate is called at a fixed interval and is independent of frame rate. Put physics code here.
    // Deixar Input no FixedUpdate pode causa input loss
    void FixedUpdate()
    {
        //Store the current horizontal input in the float moveHorizontal.
        //if(jumping)
        moveHorizontal = Input.GetAxis("Horizontal");

        //jump

        //Pose usar o Input.GetAxisRaw("Vertical") > 0
        if (jumping && Input.GetKey(KeyCode.UpArrow))
        {
            rb2d.AddForce((Vector2.up) * jumpPower, ForceMode2D.Impulse);
            jumping = false;
        }

        // Pode usar o Input.GetButtonDown("Jump")
        if (gettingItem && Input.GetKey(KeyCode.Space))
        {
            Debug.Log("pegou o item mesmo");
            item.pegaItem();
            gettingItem = false;
        }

        //Use the two store floats to create a new Vector2 variable movement.
        Vector2 movement = new Vector2(moveHorizontal, 0f);

        //Call the AddForce function of our Rigidbody2D rb2d supplying movement multiplied by speed to move our player.
        rb2d.AddForce(movement * speed);

        if (rb2d.velocity.x > 4.5f)
        {
            rb2d.velocity = new Vector2(4.5f, rb2d.velocity.y);
        }
        else if (rb2d.velocity.x < -4.5f)
        {
            rb2d.velocity = new Vector2(-4.5f, rb2d.velocity.y);
        }
    }