TransformHandle.rotation
Declaration
public Quaternion rotation;Описание
Quaternion, который хранит вращение Transform в мировом пространстве.
TransformHandle.rotation хранит Quaternion. Вы можете использовать rotation для поворота GameObject или указать текущее вращение. Не пытайтесь редактировать/модифицировать rotation. TransformHandle.rotation меньше 180 градусов.
TransformHandle.rotation не имеет блокировки гимбала.
Для поворота TransformHandle, используйте TransformHandle.Rotate, который использует Эйлеровы углы.
Если вы хотите сопоставить значения, которые вы видите в Inspector, используйте свойство Quaternion.eulerAngles на возвращаемом Quaternion.
using UnityEngine;
// Transform.rotation example.
// Rotate a GameObject using a Quaternion. // Tilt the cube using the arrow keys. When the arrow keys are released // the cube will be rotated back to the center using Slerp.
public class ExampleScript : MonoBehaviour { float smooth = 5.0f; float tiltAngle = 60.0f;
void Update() { // Smoothly tilts a transform towards a target rotation. float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle; float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
// Rotate the cube by converting the angles into a quaternion. Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
TransformHandle thisTransformHandle = transformHandle;
// Dampen towards the target rotation thisTransformHandle.rotation = Quaternion.Slerp(thisTransformHandle.rotation, target, Time.deltaTime * smooth); } }
В вышеприведённом примере rotation описаны кватернионом. Более подробно см. Вращение и ориентация в Unity.