提问人:zuzi 提问时间:8/28/2023 最后编辑:derHugozuzi 更新时间:8/28/2023 访问量:20
触摸输入系统无法在我的项目上运行
Touch Input system not working on my project
问:
您好,我正在尝试在我的安卓手机上制作自己的俄罗斯方块游戏。我正在努力做,
1-触摸和释放屏幕旋转,
2- 向下、向左和向右滑动和滑动,不进行任何旋转。
这是我的代码,任何建议都会很棒,非常感谢!
private Vector2 touchStartPos;
private bool isRotating = false;
private float swipeThreshold = 75.0f;
private void Update()
{
this.board.Clear(this);
this.lockTime += Time.deltaTime;
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
touchStartPos = touch.position;
isRotating = false;
}
else if (touch.phase == TouchPhase.Moved)
{
if (!isRotating)
{
float swipeDistance = touch.position.x - touchStartPos.x;
float verticalDistance = touch.position.y - touchStartPos.y;
if (Mathf.Abs(swipeDistance) > Mathf.Abs(verticalDistance))
{
if (Mathf.Abs(swipeDistance) > swipeThreshold)
{
if (swipeDistance > 0)
{
Debug.Log("Movement for right.");
Move(Vector2Int.right);
}
else
{
Debug.Log("Movement for left.");
Move(Vector2Int.left);
}
}
}
else if (verticalDistance < -swipeThreshold)
{
Debug.Log("Movement for down.");
Move(Vector2Int.down);
}
}
}
else if (touch.phase == TouchPhase.Ended)
{
if (!isRotating)
{
isRotating = true;
Debug.Log("Touch detected, processing.");
Rotate(1);
}
}
}
}
我在互联网上尝试了很多解决方案,但找不到解决方案。
答: 暂无答案
评论
not working