【Unity研究院】UGUI_监听右键

前一段时间用UGUI做一个小工具,需要支持右键点击

直接上代码

话不多说,直接上代码,连中键都行啊

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class RightClick : MonoBehaviour, IPointerClickHandler
{
public UnityEvent leftClick;
public UnityEvent middleClick;
public UnityEvent rightClick;
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
leftClick.Invoke();
else if (eventData.button == PointerEventData.InputButton.Middle)
middleClick.Invoke();
else if (eventData.button == PointerEventData.InputButton.Right)
rightClick.Invoke();
}
}

坚持原创技术分享,您的支持将鼓励我继续创作!