我已經在Vuforia Unity3d中使用了此腳本,但它的行爲很奇怪。如何使用觸摸輸入拖動增強模型
任何人都可以發佈腳本來拖動/移動/旋轉3D模型。
public class touchcontrol : MonoBehaviour {
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0); // get first touch since touch count is greater than zero
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
{
// get the touch position from the screen touch to world point
Vector3 touchedPos = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
// lerp and set the position of the current object to that of the touch, but smoothly over time.
transform.position = Vector3.Lerp(transform.position, touchedPos, Time.deltaTime);
}
}
}
}
不,它不起作用它會縮放物體。我必須在觸摸時拖動/旋轉沙發3D模型。 – Kushan2
我想要的東西是這樣的:https://www.youtube.com/watch?v=rSbXR5h5cRc – Kushan2
更新了代碼,這應該將對象移動到觸摸位置而不縮放。 –