Vector3 move = Vector3.zero;
if (characterController.isGrounded)
{
move.x = Input.GetAxis("Horizontal") * Time.deltaTime * Speed;
move.z = Input.GetAxis("Vertical") * Time.deltaTime * Speed;
if (Input.GetButton("Jump"))
{
move.y = JumpSpeed;
}
}
Debug.Log(characterController.isGrounded);
move.y -= Gravity * Time.deltaTime;
characterController.Move(move);
GetButton则characterController.isGrounded为True,GetKey则为False,因为出现了UnityException: Input Key named: Jump is unknown UnityEngine.Input.GetKeyDown (System.String name) ,应修改为if(Input.GetKeyDown(KeyCode.Space))
GetButtonDown才是对应虚拟按钮的,GetKeyDown只对应键值。