public Vector3 eulerAngles ;

Descripción

La rotación es ángulos Euler en grados.

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.

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;

public class Example : MonoBehaviour { // Assign an absolute rotation using eulerAngles float yRotation = 5.0f;

void Start() { // 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); }

void Update() { yRotation += Input.GetAxis("Horizontal"); transform.eulerAngles = new 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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961