📜  unity android touch slide - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:26.287000             🧑  作者: Mango

代码示例1
if (Input.touchCount > 0)
{
 theTouch = Input.GetTouch(0);

 if (theTouch.phase == TouchPhase.Began)
 {
  touchStartPosition = theTouch.position;
 }

 else if (theTouch.phase == TouchPhase.Moved || theTouch.phase == TouchPhase.Ended)
 {
  touchEndPosition = theTouch.position;

  float x = touchEndPosition.x - touchStartPosition.x;
  float y = touchEndPosition.y - touchStartPosition.y;

  if (Mathf.Abs(x) == 0 && Mathf.Abs(y) == 0)
  {
   direction = “Tapped”;
  }

  else if (Mathf.Abs(x) > Mathf.Abs(y))
  {
   direction = x > 0 ? “Right” : “Left”;
  }

  else
  {
   direction = y > 0 ? “Up” : “Down”;
  }
 }
}

directionText.text = direction;