# 无效操作异常：无法从值类型为 'Vector2' 的控件读取类型为 'float' 的值。

- **ID:** `unity/input-system-float-parameter-invalid`
- **领域:** unity
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

输入系统操作绑定到了输出 Vector2 的控件（例如摇杆），但代码试图将其作为单个 float 读取，导致类型不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2022.3.12f1 | active | — | — |
| Unity 2023.2.0b1 | active | — | — |
| Input System 1.7.0 | active | — | — |

## 解决方案

1. ```
   将操作的预期值类型更改为与控件匹配。对于 Vector2 控件，使用 `action.ReadValue<Vector2>()` 读取 Vector2 值。例如：`Vector2 move = playerInput.actions["Move"].ReadValue<Vector2>();`。
   ```
2. ```
   如果只需要一个轴，则将操作绑定到单轴控件（例如键盘按键或按钮），而不是 Vector2 摇杆，并作为 float 读取。
   ```
3. ```
   仅当操作绑定到输出单个 float 的控件（例如 Axis 控件）时，才使用 `action.ReadValue<float>()`。在输入操作资源编辑器中验证绑定。
   ```

## 无效尝试

- **** — Changing the action type to 'Pass Through' without adjusting the control binding may still result in type mismatch if the control output type is incompatible. (60% 失败率)
- **** — Disabling and re-enabling the action map does not resolve the fundamental type mismatch between the expected value type and the control's output. (90% 失败率)
