unity点击事件的三种方法:
1.Input.GetMouseButtonDown(0)//0表示鼠标左键,右键为1,滚轮为2.,鼠标左键按下时候为true,我们可以用它作为判断来实现点击事件。
但是要注意的是Input.GetMouseButtonDown只会判断一次,不能实现长按处理。(自己遇到的坑)
如果需要长按处理要用Input.GetMouseButton。当然也有Input.GetMouseButtonUp。
2.利用事件接口(动态加载)
UnityAction<BaseEventData> enter;
UnityAction<BaseEventData> exit;
UnityAction<BaseEventData> click;
EventTrigger.Entry entry;
EventTrigger.Entry entry1;
EventTrigger.Entry entry2;
EventTrigger trigger;
void Start()
{
enter = new UnityAction<BaseEventData>(OnPointerEnterDelegate);
exit = new UnityAction<BaseEventData>(OnPointerExitDelegate);
click = new UnityAction<BaseEventData>(OnPointerClickDelegate);
trigger = gameObject.AddComponent<EventTrigger>();
entry = new EventTrigger.Entry();
entry1 = new EventTrigger.Entry();
entry2 =