2015-02-12 77 views
0

我有下面的代码,并在键盘中工作,但不适用于触摸。用触摸旋转游戏对象

Quaternion rot = transform.rotation; float z = rot.eulerAngles.z;  
z-= Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime; 
rot = Quaternion.Euler(0, 0, z); 
transform.rotation = rot; 

我需要上面的代码作品在触摸,如何做到这一点?

回答

2

也许你应该阅读的API http://docs.unity3d.com/ScriptReference/Input.html

您可以使用getTouch方法旋转对象 这里的文档

http://docs.unity3d.com/ScriptReference/Input.GetTouch.html

可以使用增量为draging团结脚本的输入或旋转对象的位置

所以它会这样不知道它的工作,它应该与拖动

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { 
    Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; 
    z-=touchDeltaPosition.x * rotSpeed * Time.deltaTime; 
    rot = Quaternion.Euler(0, 0, z); 
    } 
0

应当几乎与上述相同,但代替x轴这是我们所使用的Y轴为立式一个该代码也与拖动

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { 
    Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; 
Vector3 pos = transform.position; 
Vector3 velocity = new Vector3(0, touchDeltaPoition.y * maxSpeed * Time.deltaTime, 0); 
pos += rot * velocity; 
} 
水平线在