void Move()
{
if (Input.GetKey(KeyCode.W))
{
target = rig.position + Vector2.up;
}
if (Input.GetKey(KeyCode.S))
{
target = rig.position + Vector2.down;
}
if (Input.GetKey(KeyCode.A))
{
target = rig.position + Vector2.left;
}
if (Input.GetKey(KeyCode.D))
{
target = rig.position + Vector2.right;
}
if (isMove(target))
{
rig.position = Vector2.Lerp(rig.position, target, Speed);
print(rig.position);
if (Vector2.Distance(rig.position, target) < 0.05f)
{
rig.position = target;
}
}
}
bool isMove(Vector2 targetPos)
{
RaycastHit2D hit = Physics2D.Linecast(targetPos, rig.position);
if (hit.collider.gameObject.name == "Maze")
{
return false;
}
else
{
return true;
}
}
//吃豆人的移动自己改了一下,按这种移动方式,请问为什么不会按照整数的单位移动呢