手机触屏判断

来源:互联网 发布:厂牌制作软件下载 编辑:程序博客网 时间:2024/05/17 03:03

void MobileInput()
{
      if(Input.touchCount <= 0)
      return;
      //1个手指触摸屏幕
      if (Input.touchCount == 1)
      {
 
      if(Input.touches[0].phase == TouchPhase.Began)
      {
            //记录手指触屏的位置
            m_screenpos= Input.touches[0].position;
 
      }
      // 手指移动
      else if(Input.touches[0].phase == TouchPhase.Moved)
      {
          //移动摄像机
          Camera.main.transform.Translate(newVector3(Input.touches[0].deltaPosition.x * Time.deltaTime,Input.touches[0].deltaPosition.y * Time.deltaTime, 0));
       }
      //手指离开屏幕判断移动方向
      if(Input.touches[0].phase == TouchPhase.Ended &&
      Input.touches[0].phase!= TouchPhase.Canceled)
      {
          Vector2pos = Input.touches[0].position;
          //手指水平移动
          if(Mathf.Abs(m_screenpos.x - pos.x) > Mathf.Abs(m_screenpos.y - pos.y))
          {
              if(m_screenpos.x > pos.x){
              //手指向左划动
          }
          else{
              //手指向右划动
          }
    }
    else //手指垂直移动
    {
        if(m_screenpos.y > pos.y){
        //手指向下划动
    }
    else{
        //手指向上划动
    }
}
}
0 0
原创粉丝点击