小编jus*_*fee的帖子

如何将Input.GetAxis("Mouse X")或Input.GetAxis("Mouse Y")转换为新的输入系统?

我是 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>(); …
Run Code Online (Sandbox Code Playgroud)

unity-game-engine

2
推荐指数
1
解决办法
9521
查看次数

标签 统计

unity-game-engine ×1