# Transform.rotation 旋转角度

var rotation : Quaternion

Description描述

The rotation of the transform in world space stored as a Quaternion.

Unity stores rotations as Quaternions internally. To rotate an object, use Transform.Rotate. Use Transform.eulerAngles for setting the rotation as euler angles.

Unity作为四元数内部储存旋转角度。使用Transform.Rotate来旋转一个物体，使用Transform.eulerAngles设置作为欧拉角的旋转角度。

``````using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public void Awake() {
transform.rotation = Quaternion.identity;
}
}``````
``````// Reset the world rotation
//重设世界的旋转角度
transform.rotation = Quaternion.identity;``````

``````using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public float smooth = 2.0F;
public float tiltAngle = 30.0F;
void Update() {
float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}``````
``````// Smoothly tilts a transform towards a target rotation.
//平滑倾斜物体向一个target旋转
var smooth = 2.0;
var tiltAngle = 30.0;
function Update () {
var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
var tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
// Dampen towards the target rotation
//向target旋转阻尼
transform.rotation = Quaternion.Slerp(transform.rotation, target,
Time.deltaTime * smooth);;
}``````
Page last updated: 2012-7-21