# Transform.eulerAngles 欧拉角

var eulerAngles : Vector3

Description描述

The rotation as Euler angles in degrees.

The x, y, and z angles represent a rotation z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).

x、y、z角代表绕z轴旋转z度，绕x轴旋转x度，绕y轴旋转y度（这个顺序）。

Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead.

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

public class example : MonoBehaviour {
public float yRotation = 5.0F;
void Update() {
yRotation += Input.GetAxis("Horizontal");
transform.eulerAngles = new Vector3(10, yRotation, 0);
}
public void Awake() {
print(transform.eulerAngles.x);
print(transform.eulerAngles.y);
print(transform.eulerAngles.z);
}
}``````
``````// Print the rotation around the global X Axis
//打印绕世界x轴的旋转角度
print (transform.eulerAngles.x);
// Print the rotation around the global Y Axis
//打印绕世界y轴的旋转角度
print (transform.eulerAngles.y);
// Print the rotation around the global Z Axis
//打印绕世界z轴的旋转角度
print (transform.eulerAngles.z);

// Assign an absolute rotation using eulerAngles
//指定一个绝对使用欧拉角的旋转角度
var yRotation : float = 5.0;
function Update () {
yRotation += Input.GetAxis("Horizontal");
transform.eulerAngles = Vector3(10, yRotation, 0);

}``````

Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations. When setting them to a new value set them all at once as shown above. Unity will convert the angles to and from the rotation stored in Transform.rotation

Page last updated: 2010-12-19