在屏幕上向下滑动时如何使角色向下移动到平台
How to make the character move down to platform when swiped down on the screen
我有一个角色运行向上滑动它会跳起来,一段时间后它会自动回到地面。如果我向下滑动,我需要在跳跃时添加变化,它应该会在那一刻很快下降。
private Vector3 fp;
private Vector3 lp;
private float dragDistance;
private List<Vector3> touchPositions = new List<Vector3>();
foreach (Touch touchi in Input.touches)
{
if (touchi.phase == TouchPhase.Moved)
{
touchPositions.Add(touchi.position);
}
if (touchi.phase == TouchPhase.Ended)
{
fp = touchPositions[0];
lp = touchPositions[touchPositions.Count-1];
if (Mathf.Abs (lp.x - fp.x) > dragDistance
|| Mathf.Abs (lp.y - fp.y) > dragDistance)
{
if (lp.y > fp.y)
{
jumpSpeed = 0;
enabled = InAir();
}
}
}
}
这是我的代码,但它不起作用,认为触摸检测中的一些错误甚至打印在 foreach 端不起作用。
这是一个很好的处理滑动的片段:
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
if(touchDeltaPosition.y < 0)
{
//move character down here
}
}
}
我有一个角色运行向上滑动它会跳起来,一段时间后它会自动回到地面。如果我向下滑动,我需要在跳跃时添加变化,它应该会在那一刻很快下降。
private Vector3 fp;
private Vector3 lp;
private float dragDistance;
private List<Vector3> touchPositions = new List<Vector3>();
foreach (Touch touchi in Input.touches)
{
if (touchi.phase == TouchPhase.Moved)
{
touchPositions.Add(touchi.position);
}
if (touchi.phase == TouchPhase.Ended)
{
fp = touchPositions[0];
lp = touchPositions[touchPositions.Count-1];
if (Mathf.Abs (lp.x - fp.x) > dragDistance
|| Mathf.Abs (lp.y - fp.y) > dragDistance)
{
if (lp.y > fp.y)
{
jumpSpeed = 0;
enabled = InAir();
}
}
}
}
这是我的代码,但它不起作用,认为触摸检测中的一些错误甚至打印在 foreach 端不起作用。
这是一个很好的处理滑动的片段:
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
if(touchDeltaPosition.y < 0)
{
//move character down here
}
}
}