我正在尝试通过触摸设备来拖动或移动和旋转模型。我通过单点触摸放置它,并通过双点触摸旋转它。我在模型中添加了一个名为“ Region”的标签。下面是代码。我将此脚本附加到实例化模型上。
public float rotspeed = 8f;
private RaycastHit vision;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update()
{
if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Debug.Log("Double Touch");
// Get movement of the finger since last frame
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
if(Physics.Raycast(Input.GetTouch(0).position,
this.transform.position,
out vision))
{
Debug.Log("Entered Region");
if(vision.transform.tag=="Region")
{
Debug.Log("Hit Region");
transform.Rotate(Vector3.up,
-touchDeltaPosition.x * rotspeed * Time.deltaTime,
Space.World);
transform.Rotate(Vector3.right,
touchDeltaPosition.y * rotspeed * Time.deltaTime,
Space.World);
}
}
}
}