public UnityEvent leftClick;
public UnityEvent middleClick;
public UnityEvent rightClick;
private void Start()
{
leftClick.AddListener(new UnityAction(ButtonLeftClick));
middleClick.AddListener(new UnityAction(ButtonMiddleClick));
rightClick.AddListener(new UnityAction(ButtonRightClick));
}
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();
}
private void ButtonLeftClick()
{
Debug.Log("Button Left Click");
}
private void ButtonMiddleClick()
{
Debug.Log("Button Middle Click");
}
private void ButtonRightClick()
{
Debug.Log("Button Right Click");
}
Unity中判断点击按钮时鼠标事件(左键、中键、右键)
最新推荐文章于 2024-08-06 17:37:35 发布