Certainly! Here's the modified code that only rotates around the Y-axis:

Vector3 cross = Vector3.Cross(new Vector3(eventData.delta.x, eventData.delta.y), Vector3.forward).normalized;
// Set the Y component of the cross vector to 0 to only rotate around the Y-axis
cross.y = 0f;
cross.Normalize();

// Use the modified cross vector to rotate around the Y-axis
if (_Model != null)
{
    _Model.transform.Rotate(cross, eventData.delta.magnitude * 0.3f, Space.World);
}

In this modified code, we set the Y component of the cross vector to 0 before normalizing it. This ensures that the rotation only occurs around the Y-axis

Vector3 cross = Vector3Crossnew Vector3eventDatadeltax eventDatadeltay Vector3forwardnormalized; 以和鼠标拖动平面垂直的法向量作为自转的轴 拖动距离的长度作为自转的角度 if _Model != null _Modeltra

原文地址: https://www.cveoy.top/t/topic/iR5W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录