我们在想要用于处理输入动作的类中,申明对应的 InputAction 类型的成员变量(注意:需要引用命名空间UnityEngine.InputSystem) 一、InputAction 参数 编写脚本挂载到物体上 public class Lesson7 : MonoBehaviour { [Header("Binding")] public InputAction move; [Header("1D Axis")] public InputAction axis; [Header...
旧版对于 GetAxis 会有一个平滑过渡的处理,也就是第一帧按下按键时,函数不会返回1,而是在接下来几帧返回从 0 - 1 的插值,这样物体移动的起步与拐弯都会比较平滑。 GetAxis实现的物体移动轨迹 而新版 InputSystem 通过绑定 Action 并且 ReadValue publicvoidOnInputMove(InputAction.CallbackContextcontext){_input...
private void OnMovePerformed(UnityEngine.InputSystem.InputAction.CallbackContext obj) { Vector2 moveDir = obj.ReadValue<Vector2>(); input_X = moveDir.x; input_Y = moveDir.y; if (input_X != 0 && input_Y != 0) { input_X = input_X * 0.7f; input_Y = input_Y * 0.7f; } in...
public void OnJump(InputAction.CallbackContext callbackContext) { Debug.Log("Jump"); } public void OnMove(InputAction.CallbackContext callbackContext) { var moveVec = callbackContext.ReadValue<Vector2>(); } } 在OnEnable方法中,获取物体上的PlayerInput组件,通过组件获取当前Map上的具体Action,添加...
Movement(InputAction.CallbackContext context) { // 获取鼠标移动数据 Vector2 mouseDelta = context.ReadValue<Vector2>(); Debug.Log("Mouse Movement: " + mouseDelta); // 你可以在这里处理鼠标移动,例如移动相机或物体 } void OnDisable() { // 禁用Input Actions if (mouseMovementAction !
{// 启用输入控制inputControl.Enable();}private void OnDisable(){// 禁用输入控制inputControl.Disable();}private void Update(){// 获取输入方向inputDirection = inputControl.Player.Move.ReadValue<Vector2>();}private void FixedUpdate(){Move();}//移动角色private void Move(){// 根据输入方向移动...
Input Action设置 双击新建的Input Actions或者在Inspector面板选择Edit asset,打开Input Actions编辑面板,在此面板我们可以创建一些自己的行为。 Input Actions配置界面 点击Action Maps旁边的“+”创建一个“行为映射表”,新建的Map下会带有一个空action和一个未绑定Control的Binding。下边会解释。
private void OnActionTriggered(InputAction.CallbackContext obj) { //任意输入触发都会触发此事件 Debug.Log("ActionTriggered"); switch(obj.action.name) { case "Move": Debug.Log(obj.ReadValue<Vector2>()); break; case "Jump": Debug.Log("Jump"); ...
voidInputTest(){GameInput inputAction=newGameInput();//GameInput为场景中的InputSystem控制器inputAction.Enable();inputAction.Gameplay.MouseDown.performed+=ctx=>{Debug.Log("按下:"+UnityEngine.InputSystem.Mouse.current.position.ReadValue());};inputAction.Gameplay.MouseDrag.performed+=ctx=>{Debug.Log(...