1. 获取Unity Input System中鼠标位置的基本方法 在Unity Input System中,你可以使用Mouse.current.position来获取鼠标的当前位置。这是一个InputControl<Vector2>类型的属性,它表示鼠标在屏幕上的位置。 2. 理解Unity Input System如何处理鼠标输入 Unity Input System是一
public void OnMouseDown(InputAction.CallbackContext context) { if (context.phase == InputActionPhase.Performed) {//方法1 //Set up the new Pointer Event PointerEventData m_PointerEventData = new PointerEventData(m_EventSystem); //Set the Pointer Event Position to that of the mouse position m_...
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("...
1Input.mousePosition 在使用InputSystem情况下,获取鼠标在屏幕的位置 usingUnityEngine.InputSystem; Mouse.current.position.ReadValue(); 比如在UGUI背包上拖动UI物品时,就可以在物品OnDrag方法中 1publicvoidOnDrag(PointerEventData eventData)2{3transform.position =Mouse.current.position.ReadValue();4} 这样物品就...
("Action_Move" + ctx.ReadValue<Vector2>()); }; inputActions.Player.ACTION_UP.performed += ctx => { Debug.Log("Action_Up" + UnityEngine.InputSystem.Mouse.current.position.ReadValue()); }; } void Start(){} void Update(){} private void OnDestroy() { inputActions.Disable(); } } ...
新版:Mouse.current.position; 滚轮对比 旧版: Input.GetAxis("Mouse ScrollWheel"); 新版:Mouse.current.scroll.ReadValue(); 滚轮这个地方要稍微注意一点,旧版的会直接返回一个float的值,而新版本则会返回Vector2,如果想返回float请使用Mouse.current.scroll.ReadValue().y,值得注意的是,新版返回的Y值一般都较大...
inputAction.Enable(); inputAction.Gameplay.MouseDown.performed+=ctx=> { Debug.Log("按下:"+UnityEngine.InputSystem.Mouse.current.position.ReadValue()); }; inputAction.Gameplay.MouseDrag.performed+=ctx=> { Debug.Log("拖拽:"+UnityEngine.InputSystem.Mouse.current.position.ReadValue()); ...
position.ReadValue()); } } 这也是我最不推荐的一种方法,这种写法等于直接舍弃掉了InputSystem的优点、把它当旧系统用。 实际上,InputSystem为我们封装好了一个输入类,我们可以在玩家(或者其他的)身上挂载PlayerInput类,通过绑定事件来实现玩家输入。这样的用法更像UE的(蓝图方面)输入系统了,我们也要创建一系列...
直接使用InputSystem的方法很简单,系统提供了各种设备对应的管理类和当前实例 Gamepadgamepad=GamePad.current;// 手柄Joystickjoystick=Joystick.current;// 摇杆Keyboardkeyboard=Keyboard.current;// 键盘Pointerpointer=Pointer.current;// 指针,屏幕上的指定位置操作,包括鼠标,触屏以及手写笔等子类Mousemouse=Mouse.current...
mouse.position.ReadValue(); //获取当前鼠标移动向量 mouse.delta.ReadValue() //获取鼠标中键滚轮方向向量 mouse.scroll.ReadValue() 触屏输入方法 -- 获取手指组 命名空间引用 usingUnityEngine.InputSystem; using UnityEngine.InputSystem.Controls;Touchscreentouch = Touchscreen.current;//获取当前运行环境的触控...