【发布时间】:2018-01-11 16:41:24
【问题描述】:
我有一个带有 Rigidbody2D 和圆形对撞机的玩家。玩家收集具有圆形对撞机的硬币。我左右移动播放器。当它收集硬币时,硬币会破坏并且玩家停止,所以我必须再次触摸才能继续向左/向右移动。那么,如何在不停止玩家的情况下收集硬币呢?这是我移动刚体的代码:
void TouchMove()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
float middle = Screen.width / 2;
if (touch.position.x < middle && touch.phase == TouchPhase.Began)
{
MoveLeft();
}
else if (touch.position.x > middle && touch.phase == TouchPhase.Began)
{
MoveRight();
}
}
else
{
SetVelocityZero();
}
}
public void MoveLeft()
{
rb.velocity = new Vector2(-playerSpeed, 0);
}
public void MoveRight()
{
rb.velocity = new Vector2(playerSpeed, 0);
}
public void SetVelocityZero()
{
rb.velocity = Vector2.zero;
}
【问题讨论】: