unity中的2D虚拟摇杆和3D虚拟摇杆

来源:互联网 发布:新媒体传播 网络传播 编辑:程序博客网 时间:2024/06/05 10:34

源代码链接https://github.com/hiramtan/HiJoystick_unity

如何使用

可以从此链接下载最新的unity package: Github Releases

完成功能

  • 2D虚拟摇杆
  • 3D虚拟摇杆

截屏

2D虚拟摇杆:

3D虚拟摇杆:

示例

使用 _joystick.State 获取拖拽状态:
- Start,
- Dragging,
- End,

使用 _joystick.DraggingHandler 摇杆偏移量.

public class Example : MonoBehaviour{    [SerializeField]    private Joystick _joystick;    // Update is called once per frame    void Update()    {        Debug.Log(_joystick.State);    }    void OnEnable()    {        _joystick.DraggingHandler += OnDragging;    }    void OnDisable()    {        _joystick.DraggingHandler -= OnDragging;    }    void OnDragging(Vector3 v)    {        Debug.LogWarning(v);    }}
原创粉丝点击