返回介绍

Transform.Rotate 旋转

发布于 2019-12-18 15:38:41 字数 4611 浏览 1174 评论 0 收藏 0

JavaScript => Rotate(eulerAngles: Vector3, relativeTo: Space = Space.Self): void;
C# => void Rotate(Vector3 eulerAngles, Space relativeTo = Space.Self);

Description 描述

Applies a rotation of /eulerAngles.z/ degrees around the z axis, /eulerAngles.x/ degrees around the x axis, and /eulerAngles.y/ degrees around the y axis (in that order).

应用一个欧拉角的旋转角度,eulerAngles.z度围绕z轴,eulerAngles.x度围绕x轴,eulerAngles.y度围绕y轴(这样的顺序)。

If relativeTo is left out or set to Space.Self the rotation is applied around the transform's local axes. (The x, y and z axes shown when selecting the object inside the Scene View.) If relativeTo is Space.World the rotation is applied around the world x, y, z axes.

如果相对于留空或者设置为Space.Self 旋转角度被应用围绕变换的自身轴。(当在场景视图选择物体时,x、y和z轴显示)如果相对于 Space.World 旋转角度被应用围绕世界的x、y、z轴。

JavaScript:

function Update() {
	// Slowly rotate the object around its X axis at 1 degree/second.
	transform.Rotate(Vector3.right * Time.deltaTime);
 
	// ... at the same time as spinning relative to the global 
	// Y axis at the same speed. 
	transform.Rotate(Vector3.up * Time.deltaTime, Space.World); 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        transform.Rotate(Vector3.right * Time.deltaTime);
        transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
    }
}

JavaScript => Rotate(xAngle: float, yAngle: float, zAngle: float, relativeTo: Space = Space.Self): void;
C# => void Rotate(float xAngle, float yAngle, float zAngle, Space relativeTo = Space.Self);

Description 描述

Applies a rotation of zAngle degrees around the z axis, xAngle degrees around the x axis, and yAngle degrees around the y axis (in that order).

应用一个旋转角度,zAngle度围绕z轴,xAngle度围绕x轴,yAngle度围绕y轴(这样的顺序)。

If relativeTo is left out or sot to Space.Self the rotation is applied around the transform's local axes. (The x, y and z axes shown when selecting the object inside the Scene View.) If relativeTo is Space.World the rotation is applied around the world x, y, z axes.

如果相对于留空或者设置为Space.Self 旋转角度被应用围绕变换的自身轴。(当在场景视图选择物体时,x、y和z轴显示)如果相对于 Space.World 旋转角度被应用围绕世界的x、y、z轴。

JavaScript:

function Update() {
	// Slowly rotate the object around its X axis at 1 degree/second.
	transform.Rotate(Time.deltaTime, 0, 0);
 
	// ... at the same time as spinning it relative to the global 
	// Y axis at the same speed. 
	transform.Rotate(0, Time.deltaTime, 0, Space.World); 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        transform.Rotate(Time.deltaTime, 0, 0);
        transform.Rotate(0, Time.deltaTime, 0, Space.World);
    }
}

JavaScript => Rotate(axis: Vector3, angle: float, relativeTo: Space = Space.Self): void;
C# => void Rotate(Vector3 axis, float angle, Space relativeTo = Space.Self);

Description 描述

Rotates the transform around axis by angle degrees.

按照angle度围绕axis轴旋转变换。

If relativeTo is left out or set to Space.Self the axis parameter is relative to the transform's local axes. (The x, y and z axes shown when selecting the object inside the Scene View.) If relativeTo is Space.World the axis parameter is relative to the world x, y, z axes.

如果相对于留空或者设置为Space.Self 旋转角度被应用围绕变换的自身轴。(当在场景视图选择物体时,x、y和z轴显示)如果相对于 Space.World 旋转角度被应用围绕世界的x、y、z轴。

JavaScript:

function Update() {
 
    // Slowly rotate the object around its X axis at 1 degree/second.
 
    transform.Rotate(Vector3.right, Time.deltaTime);
 
    // ... at the same time as spinning it relative to the global 
    // Y axis at the same speed. 
    transform.Rotate(Vector3.up, Time.deltaTime, Space.World); 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        transform.Rotate(Vector3.right, Time.deltaTime);
        transform.Rotate(Vector3.up, Time.deltaTime, Space.World);
    }
}

Transform

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文