if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved && move == true)
{
float xm = transform.position.x;
float ym = transform.position.y;
float x = Input.GetTouch(0).deltaPosition.x;
float y = Input.GetTouch(0).deltaPosition.y; //最关键的是在这里,这里是deltaPositon不是position
if (xm > 2f)
{
xm = 2;
}
if (ym > 2)
{
ym = 2;
}
if (xm < -2)
{
xm = -2;
}
if (ym < -2)
{
ym = -2;
}
transform.position = new Vector3(xm, ym, 0); 这里是限制物体的移动区域
transform.Translate(Vector3.up * y / 100, Space.World);
transform.Translate(Vector3.left * x / 100, Space.World);
}