我有一个向左或向右旋转的物体,当用户将手指拖到它上面时,在iPad4上,它可以非常流畅地工作。
然而,在iPhone 6 Plus或Nexus 4上有一个非常明显的滞后响应拖动到某一点,有时几乎不会旋转?
这就是我在更新方法中所拥有的...我做错了什么,确保轮换感觉并且在各种设备上看起来都一样?
void Update () {
// test for touch
if (Input.touchCount == 1) {
// grab reference to this touch
Touch userTouch = Input.GetTouch(0);
// ray from cameara to point of finger touch
Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(0).position );
// hit object to record details of what was hit (touched)
RaycastHit hit;
// if the hit was on the Collider object
if ( Physics.Raycast(ray, out hit) && hit.collider.gameObject.name == "MyObject") {
// process the relavent phase...
if (userTouch.phase == TouchPhase.Began) {
}
else if (userTouch.phase == TouchPhase.Moved) {
// user is moving finger so rotate model
transform.Rotate(0.0f, -userTouch.deltaPosition.x * _rotationSpeed, 0, Space.Self);
}
else if (userTouch.phase == TouchPhase.Ended || userTouch.phase == TouchPhase.Canceled) {
}
}
}
}
答案 0 :(得分:1)
-userTouch.deltaPosition.x * _rotationSpeed * time.deltaTime
<强> time.deltaTime 强>
time.deltaTime将确保与帧速率没有相关性,因为&#34; deltaTime&#34;指的是从最后一帧传递了多少时间。常用的方法是在Update方法中对计算添加time.deltaTime,尤其是那些涉及移动或计时的方法