首页 文章

如何在Unity中使用单指触摸手势旋转对象

提问于
浏览
1

我正在Unity for Android移动平台上开发一个应用程序 . 在这个脚本的帮助下,我用单指触摸手势旋转物体,

using UnityEngine;

public class MouseDragRotate : MonoBehaviour {
    float rotationSpeed = 0.02f;

    void OnMouseDrag()
    {
         float XaxisRotation = Input.GetAxis("Mouse X")*rotationSpeed;
         float YaxisRotation = Input.GetAxis("Mouse Y")*rotationSpeed;
         // select the axis by which you want to rotate the GameObject
         transform.RotateAround (Vector3.down, XaxisRotation);
         transform.RotateAround (Vector3.right, YaxisRotation);
    }
}

但问题在于,此脚本仅适用于所有Unity资产,例如cube,sphere,capsule等 . 但不使用第三方3d对象,

那么问题就是为什么这个脚本不能用于第三方3d对象?

2 回答

  • 1

    你必须将某种 Collider 附加到你想要与之交互的3d模型/对象上 . 您可以做的是将 BoxCollider 添加到任何导入的对象,或者如果附加了 MeshFilter ,您还可以添加 MeshCollider .

  • 1

    您应确保您显示的脚本已添加到右侧顶级对象,而不是该对象的嵌套组件中 . 如果您仍然遇到问题,请向我们展示您尝试应用此对象的更多信息 . 以及为其设置了哪些组件和选项 .

相关问题