gpt4 book ai didi

c# - Input.GetAxis ("Mouse X"), Input.GetAxis ("Mouse Y") 总是返回 0

转载 作者:行者123 更新时间:2023-11-30 17:26:26 25 4
gpt4 key购买 nike

我为 3d 射击游戏添加了主要用户对象,为其附加了摄像头,并试图在脚本代码中捕捉鼠标移动,附加到玩家游戏对象。但是不能使用Input.GetAxis("Mouse X")Input.GetAxis("Mouse Y"),因为它们总是零。为什么?我做错了什么? Input.GetAxis("Vertical")Input.GetAxis("Horizo​​ntal") 键效果很好。

using UnityEngine;
using System.Collections;

public class MouseLook : MonoBehaviour {

public enum RotationAxes {
MouseXAndY = 0,
MouseX = 1,
MouseY = 2
}

public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityHor = 9.0f;
public float sensitivityVert = 9.0f;
public float minimumVert = -45.0f;
public float maximumVert = 45.0f;
private float _rotationX = 0;

void Start() {
Rigidbody body = GetComponent<Rigidbody>();
if (body != null)
body.freezeRotation = true;
}

void Update() {
Debug.Log(Input.GetAxis("Mouse X"));
Debug.Log(Input.GetAxis("Mouse Y"));
if (axes == RotationAxes.MouseX) {
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityHor, 0);
} else if (axes == RotationAxes.MouseY) {
_rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
float rotationY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
} else {
_rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
float delta = Input.GetAxis("Mouse X") * sensitivityHor;
float rotationY = transform.localEulerAngles.y + delta;
}

我希望 Input.GetAxis("Mouse X") 的输出是从 -1 到 1,但实际输出是 0。我在 Debug.Log< 中看到它.

最佳答案

检查你的统一输入设置,Mouse XMouse Y 应该定义如下:

enter image description here

关于c# - Input.GetAxis ("Mouse X"), Input.GetAxis ("Mouse Y") 总是返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56578634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com