Unity3d 人物的跳跃

果然谷歌就是无敌, 不过都是定位到unity的community里的

void Update(){
        // Jump
        if (Input.GetButtonDown("Jump"))
        {
            if (grounded == true)
            {
                float h = Input.GetAxis("Horizontal"); // A D
                float v = Input.GetAxis("Vertical"); // W S

                //Debug.Log(h + " " + v);
                if (Input.GetKey("w"))
                {
                    playerRigidbody.velocity = transform.forward * (v * speed);
                }
                if (Input.GetKey("s"))
                {
                    playerRigidbody.velocity = transform.forward * (v * speed);
                }
                if (Input.GetKey("a"))
                {
                    playerRigidbody.velocity = transform.right * (h * speed);
                }
                if (Input.GetKey("d"))
                {
                    playerRigidbody.velocity = transform.right * (h * speed);
                }
                playerRigidbody.AddForce(new Vector3(0f, jumpForce, 0f));
                grounded = false;
            }
        }
}

你可能感兴趣的:(unity3d)