public void Translate (Vector3 translation);
public void Translate (Vector3 translation, Space relativeTo= Space.Self);

描述

根据 translation 的方向和距离移动变换。

如果 relativeTo 被省略或设置为 Space.Self,则会相对于变换的本地轴来应用该移动。(在场景视图中选择对象时显示的 X、Y 和 Z 轴。) 如果 relativeToSpace.World,则相对于世界坐标系应用该移动。

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 relativeTo= Space.Self);

描述

将变换沿 X 轴移动 /x/、沿 Y 轴移动 /y/、沿 Z 轴移动 /z/。

如果 relativeTo 被省略或设置为 Space.Self,则会相对于变换的本地轴来应用该移动。(在场景视图中选择对象时显示的 X、Y 和 Z 轴。) 如果 relativeToSpace.World,则相对于世界坐标系应用该移动。

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