if (Input.touchCount == 1)
{
Touch firstTouch = Input.GetTouch(0);
//判断是否当前物体
if (firstTouch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(firstTouch.position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
//获取当前触摸到的物体
currTouchObj = hit.collider.transform;
}
}
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
//如果移动触摸了当前物体
if (currTouchObj)
{
//控制移动
Vector3 touchDeltaPos = Input.GetTouch(0).deltaPosition;
currTouchObj.Translate(touchDeltaPos.x * touchObjMoveSpeed, touchDeltaPos.y * touchObjMoveSpeed, 0, Space.World);
}
}
}