我是 Unity 脚本的新手,我正在尝试制作 ThirdPersonCamera,因此按照本教程,他可以正确地上下左右移动鼠标
使用的脚本是
posY += Input.GetAxis("Mouse X") * mouseSensitivity;
posX -= Input.GetAxis("Mouse Y") * mouseSensitivity;
// mouseSensitivity can be changed
Vector3 targetRotation = new Vector3(posX, posY);
transform.eulerAngles = targetRotation;
Run Code Online (Sandbox Code Playgroud)
由于新的输入系统,使用Input.GetAxis("Mouse X")
会引发InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings
错误。
所以我尝试使用
private PlayerInputMovement inputCamera;
void Awake(){
inputCamera = new PlayerInputMovement();
inputCamera.Player.Camera.performed += context => cameraInput = context.ReadValue<Vector2>();
}
void Update(){
Camera();
}
void Camera(){
posY += cameraInput.x * mouseSensitivity;
posX -= cameraInput.y * mouseSensitivity;
// mouseSensitivity can be changed
Vector3 targetRotation = new Vector3(posX, posY);
transform.eulerAngles = targetRotation;
}
Run Code Online (Sandbox Code Playgroud)
明白了,但是如果我将鼠标保持在一个轴上,它就会不断旋转到那一侧
那么...这是替换旧输入系统Input.GetAxis("Mouse X")
或Input.GetAxis("Mouse Y")
新输入系统的正确方法吗?我怎样才能阻止它继续旋转?
Mouse.current.delta.x.ReadValue()
Mouse.current.delta.y.ReadValue()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9521 次 |
最近记录: |