【问题标题】:Unity - How to rotate an object based on touch?Unity - 如何根据触摸旋转对象?
【发布时间】:2014-03-16 00:52:44
【问题描述】:

我正在为 iOS 设备创建游戏。我希望我的玩家或游戏对象根据触摸旋转。我在 touchPhase.Moved 中使用以下代码

if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) 
    {
        coinTouched = true;

        if (coinTouched) 
        {
            Vector2 currentTouchPosition = Input.GetTouch (0).position;
            endPos = new Vector3 (currentTouchPosition.x, 0, currentTouchPosition.y);
            endTime = Time.time;


            gameObject.transform.rotation = Quaternion.Euler(0f,Input.GetTouch(0).deltaPosition.x * 1.0f,0f);

        }

    }

但它的行为很尴尬。它旋转了几乎 180 度,然后向相反的方向移动,再经过 180 度后,它向相反的方向旋转,依此类推。请帮帮我。

谢谢。

【问题讨论】:

    标签: c# ios unity3d game-physics unityscript


    【解决方案1】:

    您的代码有点奇怪。这意味着您在 Vecotr 的错误位置使用了 x 和 y 值。我将假设您是故意这样做的,以使立方体正确转动。我会使用 Rotate 而不是更改旋转值。

    这是一个比我能做的更好的事情: http://answers.unity3d.com/questions/255118/rotating-an-object-with-touch.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多