# Transform.Translate 平移

function Translate (translation : Vector3, relativeTo : Space = Space.Self) : void

Description描述

Moves the transform in the direction and distance of translation.

If relativeTo is left out or set to Space.Self 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 the movement is applied relative to the world coordinate system.

``````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 = Space.Self) : void

Description描述

Moves the transform by x along the x axis, y along the y axis, and z along the z axis.

If relativeTo is left out or set to Space.Self 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 the movement is applied relative to the world coordinate system.

``````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, relativeTo : Transform) : void

Description描述

Moves the transform in the direction and distance of 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.

``````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) : void

Description描述

Moves the transform by x along the x axis, y along the y axis, and z along the z axis.

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.

``````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);
}``````
Page last updated: 2010-12-19