U3D 精灵的点击监听

U3D游戏中,可能会用到点击对象,完成某项操作,

方法一:可以通过接收Input对象的输入,进行利用

方法二:给对象绑定一个collier 组件,然后就能后使用内置方法

这里有点不同,方法一,是不管哪里点击都能够触发,方法二,点击对象才能进行触发。

    void OnMouseDown() {
        print("鼠标按下了");
    }

只要给精灵绑定这个组件,那么鼠标的一系列的操作就都可以完成

OnMouseDown    OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
OnMouseDrag    OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
OnMouseEnter    Called when the mouse enters the GUIElement or Collider.
OnMouseExit    Called when the mouse is not any longer over the GUIElement or Collider.
OnMouseOver    Called every frame while the mouse is over the GUIElement or Collider.
OnMouseUp    OnMouseUp is called when the user has released the mouse button.
OnMouseUpAsButton
原文地址:https://www.cnblogs.com/sunxun/p/5080498.html