UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Transform.Translate
# [Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html).Translate public void **Translate** ([Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **translation**); public void **Translate** ([Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **translation**, [Space](https://docs.unity3d.com/cn/2019.4/ScriptReference/Space.html) **relativeTo**= Space.Self); ## 描述 根据 `translation` 的方向和距离移动变换。 如果 `relativeTo` 被省略或设置为 [Space.Self](https://docs.unity3d.com/cn/2019.4/ScriptReference/Space.Self.html),则会相对于变换的本地轴来应用该移动。(在场景视图中选择对象时显示的 X、Y 和 Z 轴。) 如果 `relativeTo` 为 [Space.World](https://docs.unity3d.com/cn/2019.4/ScriptReference/Space.World.html),则相对于世界坐标系应用该移动。 ``` using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { // Move the object forward along its z axis 1 unit/second. transform.Translate(Vector3.forward * Time.deltaTime); // Move the object upward in world space 1 unit/second. transform.Translate(Vector3.up * Time.deltaTime, Space.World); } } ``` --- public void **Translate** (float **x**, float **y**, float **z**); public void **Translate** (float **x**, float **y**, float **z**, [Space](https://docs.unity3d.com/cn/2019.4/ScriptReference/Space.html) **relativeTo**= Space.Self); ## 描述 将变换沿 X 轴移动 /x/、沿 Y 轴移动 /y/、沿 Z 轴移动 /z/。 如果 `relativeTo` 被省略或设置为 [Space.Self](https://docs.unity3d.com/cn/2019.4/ScriptReference/Space.Self.html),则会相对于变换的本地轴来应用该移动。(在场景视图中选择对象时显示的 X、Y 和 Z 轴。) 如果 `relativeTo` 为 [Space.World](https://docs.unity3d.com/cn/2019.4/ScriptReference/Space.World.html),则相对于世界坐标系应用该移动。 ``` using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { // Move the object forward along its z axis 1 unit/second. transform.Translate(0, 0, Time.deltaTime); // Move the object upward in world space 1 unit/second. transform.Translate(0, Time.deltaTime, 0, Space.World); } } ``` --- public void **Translate** ([Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **translation**, [Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html) **relativeTo**); ## 描述 根据 `translation` 的方向和距离移动变换。 相对于 `relativeTo` 的本地坐标系应用移动。 如果 `relativeTo` 为 null,则相对于世界坐标系应用移动。 ``` using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { // Move the object to the right relative to the camera 1 unit/second. transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform); } } ``` --- public void **Translate** (float **x**, float **y**, float **z**, [Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html) **relativeTo**); ## 描述 将变换沿 X 轴移动 /x/、沿 Y 轴移动 /y/、沿 Z 轴移动 /z/。 相对于 `relativeTo` 的本地坐标系应用移动。 如果 `relativeTo` 为 null,则相对于世界坐标系应用移动。 ``` using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { // Move the object to the right relative to the camera 1 unit/second. transform.Translate(Time.deltaTime, 0, 0, Camera.main.transform); } } ```
da
2022年6月21日 11:41
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码