void MouseInput() { if (Input.GetMouseButtonDown(0)) { m_screenPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); //如果按太下面就不旋轉 if (m_screenPos.y < 200) { return; } isTouch = true; } if (Input.GetMouseButtonUp(0)) { m_Jtouch = new Jtouch(); isTouch = false; touchlasttime = 0; // Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // gDefine.Direction mDirection = HandDirection(m_screenPos, pos); // Debug.Log("mDirection: " + mDirection.ToString()); } if (Input.GetMouseButton(0)) { Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); m_Jtouch = HandDirection(m_screenPos, pos); m_screenPos = pos; } }
}//end void /*gDefine.Direction*/ Jtouch HandDirection(Vector2 StartPos, Vector2 EndPos) { //gDefine.Direction mDirection; Jtouch mJtouch = new Jtouch(); //print (StartPos+" "+Screen.width); //手指水平移動 if (Mathf.Abs(StartPos.x - EndPos.x) > Mathf.Abs(StartPos.y - EndPos.y)) { if (StartPos.x > EndPos.x) { //手指向左滑動 //mDirection = gDefine.Direction.Left; mJtouch.Direction = GameEnum.Direction.Left; } else { //手指向右滑動 //mDirection = gDefine.Direction.Right; mJtouch.Direction = GameEnum.Direction.Right; } if (StartPos.y > Screen.height / 2) { mJtouch.x_Distance = StartPos.x - EndPos.x; } else { mJtouch.x_Distance = (StartPos.x - EndPos.x) * -1; } mJtouch.y_Distance = 0; } else { if (m_screenPos.y > EndPos.y) { //手指向下滑動 //mDirection = gDefine.Direction.Down; mJtouch.Direction = GameEnum.Direction.Down; } else { //手指向上滑動 //mDirection = gDefine.Direction.Up; mJtouch.Direction = GameEnum.Direction.Up; } mJtouch.x_Distance = 0; if (StartPos.x > Screen.width / 2) { mJtouch.y_Distance = StartPos.y - EndPos.y; } else { mJtouch.y_Distance = (StartPos.y - EndPos.y) * -1; } } return(mJtouch); //return mDirection; }