您的位置:首页 > 移动开发 > Unity3D

Unity3D判断鼠标向右或向左滑动,响应不同的事件

2014-08-15 17:18 525 查看
private var first = Vector2.zero;   

private var second = Vector2.zero;   

function Update ()

{

}   

function OnGUI ()

{

   if(Event.current.type == EventType.MouseDown)

  {

    //记录鼠标按下的位置   

     first = Event.current.mousePosition ;

   }   

   if(Event.current.type == EventType.MouseDrag)

  {

    //记录鼠标拖动的位置   

    second = Event.current.mousePosition ;   

    if(second.x<first.x)

    {

      //拖动的位置的x坐标比按下的位置的x坐标小时,响应向左事件   

       print("left");   

     }   

     if(second.x>first.x)

    {

      //拖动的位置的x坐标比按下的位置的x坐标大时,响应向右事件   

       print("right");   

     }   

     first = second;   

  }   

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: