我希望在用户按下某个按钮时使鼠标不可见,而在用户移动鼠标时使光标可见。我已经完成了第一部分,但是我不知道如何跟踪鼠标的运动。我正在使用C#。这是我的代码
void Update()
{
if (characterController.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = new Vector2(Input.GetAxis("Horizontal"), 0.0f);
moveDirection *= speed;
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
if (Input.GetKey(KeyCode.W)) {
moveDirection.y = jumpSpeed;
}
if (Input.GetKey(KeyCode.UpArrow)) {
moveDirection.y = jumpSpeed;
} else if (!characterController.isGrounded) {
moveDirection.x = Input.GetAxis("Horizontal") * speed;
}
}
if ((Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A) || Input.GetButton("Jump") || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) && Cursor.visible) {
Cursor.visible = false;
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
}