給自己的垃圾獨立游戲做了一個簡單地背包系統,因為用了InputSystem,原來獲取鼠標位置的方式不能用了,記錄一下.
在原來的通用輸入系統下,獲取鼠標在屏幕上的位置只需要
1 Input.mousePosition
在使用InputSystem情況下,獲取鼠標在屏幕的位置
using UnityEngine.InputSystem;
Mouse.current.position.ReadValue();
比如在UGUI背包上拖動UI物品時,就可以在物品OnDrag方法中
1 public void OnDrag(PointerEventData eventData) 2 { 3 transform.position = Mouse.current.position.ReadValue(); 4 }
這樣物品就跟着鼠標跑啦
寫的真是隨便,不可取不可取