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. UnityStandardAssets.CrossPlatformInput.PlatformSpecific.StandaloneInput.GetA
时间: 2024-04-12 19:27:24 浏览: 203
failed to read input
5星 · 资源好评率100%
pKey is causing the InvalidOperationException because you are trying to read input using the old UnityEngine.Input class, but you have switched to the new Input System package in Player Settings. To fix this issue, you need to update your code to use the new Input System API for reading input.
Here's an example of how you can read input using the new Input System:
```csharp
using UnityEngine;
using UnityEngine.InputSystem;
public class YourScript : MonoBehaviour
{
private PlayerControls controls;
private void Awake()
{
controls = new PlayerControls();
}
private void OnEnable()
{
controls.Enable();
}
private void OnDisable()
{
controls.Disable();
}
private void Update()
{
float inputValue = controls.YourActionMap.YourInputControl.ReadValue<float>();
// Do something with the input value
}
}
```
In this example, `YourActionMap` refers to the action map you have defined in the Input System settings, and `YourInputControl` refers to the specific input control you want to read.
Make sure you have properly set up your Input System settings in the Unity Editor and defined the necessary action maps and input controls.
阅读全文