Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Transform.Translate 平移
# [Transform](Transform.html).Translate 平移 function *Translate* (*translation* : [Vector3](../Vector3/Vector3.html), *relativeTo* : [Space](../Enumerations/Space/Space.html) = [Space.Self](../Enumerations/Space/Space.Self.html)) : void *Description* 描述 Moves the transform in the direction and distance of translation. 移动 transform 在 translation 的方向和距离。 简单的说,向某方向移动物体多少距离。 If relativeTo is left out or set to [Space.Self](../Enumerations/Space/Space.Self.html) the movement is applied 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](../Enumerations/Space/Space.Self.html) the movement is applied relative to the world coordinate system. 如果 relativeTo 留空或者设置为 [Space.Self](../Enumerations/Space/Space.Self.html),移动被应用相对于变换的自身轴。(当在场景视图选择物体时,x、y 和 z 轴显示)如果相对于 [Space.World](../Enumerations/Space/Space.Self.html) 移动被应用相对于世界坐标系统。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { transform.Translate(Vector3.forward * Time.deltaTime); transform.Translate(Vector3.up * Time.deltaTime, Space.World); } } ``` ``` function Update() { // Move the object forward along its z axis 1 unit/second. //沿着z轴1单位/秒,向前移动物体 transform.Translate(Vector3.forward * Time.deltaTime); // Move the object upward in world space 1 unit/second. //在世界坐标沿着y轴1单位/秒,向上移动物体 transform.Translate(Vector3.up * Time.deltaTime, Space.World); } ``` • function *Translate* (*x* : float, *y* : float, *z* : float, *relativeTo* : [Space](../Enumerations/Space/Space.html) = [Space.Self](../Enumerations/Space/Space.Self.html)) : void *Description* 描述 Moves the transform by x along the x axis, y along the y axis, and z along the z axis. 移动变换由 x 沿着 x 轴,y 沿着 y 轴,z 沿着 z 轴。 If relativeTo is left out or set to [Space.Self](../Enumerations/Space/Space.Self.html) the movement is applied 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](../Enumerations/Space/Space.Self.html) the movement is applied relative to the world coordinate system. 如果 relativeTo 留空或者设置为 [Space.Self](../Enumerations/Space/Space.Self.html),移动被应用相对于变换的自身轴。(当在场景视图选择物体时,x、y 和 z 轴显示)如果相对于 [Space.World](../Enumerations/Space/Space.Self.html) 移动被应用相对于世界坐标系统。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { transform.Translate(0, 0, Time.deltaTime); transform.Translate(0, Time.deltaTime, 0, Space.World); } } ``` ``` function Update() { // Move the object forward along its z axis 1 unit/second. //沿着z轴每秒1单位向前移动物体 transform.Translate(0, 0, Time.deltaTime); // Move the object upward in world space 1 unit/second. //在世界坐标每秒1单位向上移动物体 transform.Translate(0, Time.deltaTime, 0, Space.World); } ``` • function *Translate* (*translation* : [Vector3](../Vector3/Vector3.html), *relativeTo* : [Transform](Transform.html)) : void *Description* 描述 Moves the transform in the direction and distance of translation. 移动 transform 在 translation 的方向和距离。 简单的说,向某方向移动物体多少距离。 The movement is applied relative to /relativeTo/'s local coordinate system. If relativeTo is null, the movement is applied relative to the world coordinate system. 移动被应用相对于(*relativeTo* : [Transform](Transform.html))的自身坐标系统。日光相对于为 null,则移动被应用相对于世界坐标系统。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform); } } ``` ``` function Update() { // Move the object to the right relative to the camera 1 unit/second. //相对于摄像机每秒1单位向右移动物体 transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform); } ``` • function *Translate* (*x* : float, *y* : float, *z* : float, *relativeTo* : [Transform](Transform.html)) : void *Description* 描述 Moves the transform by x along the x axis, y along the y axis, and z along the z axis. 移动变换由 x 沿着 x 轴,y 沿着 y 轴,z 沿着 z 轴。 The movement is applied relative to /relativeTo/'s local coordinate system. If relativeTo is null, the movement is applied relative to the world coordinate system. 移动被应用相对于(*relativeTo* : [Transform](Transform.html))的自身坐标系统。日光相对于为 null,则移动被应用相对于世界坐标系统。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { transform.Translate(Time.deltaTime, 0, 0, Camera.main.transform); } } ``` ``` function Update() { // Move the object to the right relative to the camera 1 unit/second. //相对于摄像机每秒1单位向右移动物体 transform.Translate(Time.deltaTime, 0, 0, Camera.main.transform); } ```
da
2022年5月23日 14:52
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码