Translate
Moves the transform along its x, y, and z axes by the values of the translation parameter's x, y, and z components respectively.
Read time 5 minutesLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
Translate(Vector3, Space)
Moves the transform along its x, y, and z axes by the values of the translation parameter's x, y, and z components respectively.
public void Translate(Vector3 translation, Space relativeTo)
Parameters
Remarks
If 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 is Space.World the movement is applied relative to the world coordinate system.
relativeTorelativeToExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Update() { // Move the object forward along its z axis 1 unit/second. transformHandle.Translate(Vector3.forward * Time.deltaTime); // Move the object upward in world space 1 unit/second. transformHandle.Translate(Vector3.up * Time.deltaTime, Space.World); }}
Translate(Vector3)
Moves the transform along its x, y, and z axes by the values of the translation parameter's x, y, and z components respectively.
public void Translate(Vector3 translation)
Parameters
The amount by which to move the Transform.
Remarks
If 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 is Space.World the movement is applied relative to the world coordinate system.
relativeTorelativeToExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Update() { // Move the object forward along its z axis 1 unit/second. transformHandle.Translate(Vector3.forward * Time.deltaTime); // Move the object upward in world space 1 unit/second. transformHandle.Translate(Vector3.up * Time.deltaTime, Space.World); }}
Translate(float, float, float, Space)
Moves the transform by x along the x axis, y along the y axis, and z along the z axis.
public void Translate(float x, float y, float z, Space relativeTo)
Parameters
Remarks
If 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 is Space.World the movement is applied relative to the world coordinate system.
relativeTorelativeToExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Update() { // Move the object forward along its z axis 1 unit/second. transformHandle.Translate(0, 0, Time.deltaTime); // Move the object upward in world space 1 unit/second. transformHandle.Translate(0, Time.deltaTime, 0, Space.World); }}
Translate(float, float, float)
Moves the transform by x along the x axis, y along the y axis, and z along the z axis.
public void Translate(float x, float y, float z)
Parameters
Remarks
If 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 is Space.World the movement is applied relative to the world coordinate system.
relativeTorelativeToExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Update() { // Move the object forward along its z axis 1 unit/second. transformHandle.Translate(0, 0, Time.deltaTime); // Move the object upward in world space 1 unit/second. transformHandle.Translate(0, Time.deltaTime, 0, Space.World); }}
Translate(Vector3, TransformHandle)
Moves the transform along its x, y, and z axes by the values of the translation parameter's x, y, and z components respectively.
public void Translate(Vector3 translation, TransformHandle relativeTo)
Parameters
The amount by which to move the Transform.
Defines the coordinate system used for the translation.
Remarks
The movement is applied relative to relativeTo's local coordinate system. If is TransformHandle.None, the movement is applied relative to the world coordinate system.
relativeToExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Update() { // Move the object to the right relative to the camera 1 unit/second. transformHandle.Translate(Vector3.right * Time.deltaTime, Camera.main.transformHandle); }}
Translate(float, float, float, TransformHandle)
Moves the transform by x along the x axis, y along the y axis, and z along the z axis.
public void Translate(float x, float y, float z, TransformHandle relativeTo)
Parameters
The amount by which to move the Transform on the x-axis.
The amount by which to move the Transform on the y-axis.
The amount by which to move the Transform on the z-axis.
Defines the coordinate system used for the translation.
Remarks
The movement is applied relative to relativeTo's local coordinate system. If is TransformHandle.None, the movement is applied relative to the world coordinate system.
relativeToExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Update() { // Move the object to the right relative to the camera 1 unit/second. transformHandle.Translate(Time.deltaTime, 0, 0, Camera.main.transformHandle); }}