Transform.eulerAngles 欧拉角

var eulerAngles : Vector3


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).


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 the rotation around the global X Axis
print (transform.eulerAngles.x);
// Print the rotation around the global Y Axis
print (transform.eulerAngles.y);
// Print the rotation around the global Z Axis
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

不要分别设置欧拉角其中一个轴(例如: eulerAngles.x = 10; ),因为这将导致偏移和不希望的旋转。当设置它们一个新的值时,要同时设置全部,如上所示。Unity会从Transform.rotation这个四元组结构中转换角度到欧拉角的表达方式,或者反过来。

Page last updated: 2010-12-19