首页 > 解决方案 > How to Rotate camera only in X-axis with mouse click and drag?

问题描述

How do I rotate camera around the X-axis only?

The below code does not function only in X-axis but in all axes.

void Update()
    {
        if (Input.GetMouseButton(1))
        {
                float XaxisRotation = Input.GetAxis("Mouse X")*rotationSpeed;
               transform.RotateAround (Vector3.right, XaxisRotation);


        }
    }

标签: c#unity3d

解决方案


RotateAround()之前使用过函数,所以相机在所有 3 个轴上旋转。仅Rotate()与 Vector3.right 一起使用会使相机仅在 X 轴上旋转。

void Update()
    {
        if (Input.GetMouseButton(1))
        {
               float XaxisRotation = Input.GetAxis("Mouse X")*10f;
               transform.Rotate (Vector3.right, XaxisRotation);

        }
}

推荐阅读