你可以像这样使用transform.rotation:
transform.rotation = new Quaternion(rotx, roty, rotz, rotw);
或
你可以像这样使用transform.Rotate:
transform.Rotate(rotx, roty, rotz);
Documentation for Quaternion
Documentation for transform.rotation
带有加速度计输入的旋转屏幕示例:
float accelx, accely, accelz = 0;
void Update ()
{
accelx = Input.acceleration.x;
accely = Input.acceleration.y;
accelz = Input.acceleration.z;
transform.Rotate (accelx * Time.deltaTime, accely * Time.deltaTime, accelz * Time.deltaTime);
}
如果要将对象旋转到特定角度,请使用:
float degrees = 90;
Vector3 to = new Vector3(degrees, 0, 0);
transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, to, Time.deltaTime);
这将围绕 x 轴旋转 90 度。