Inherits from Component,IEnumerable
Position, rotation and scale of an object.
物体的位置、旋转和缩放。
Every object in a scene has a Transform. It's used to store and manipulate the position, rotation and scale of the object. Every Transform can have a parent, which allows you to apply position, rotation and scale hierarchically. This is the hierarchy seen in the Hierarchy pane. They also support enumerators so you can loop through children using:
场景中的每一个物体都有一个Transform。用于储存并操控物体的位置、旋转和缩放。每一个Transform可以有一个父级,允许你分层次应用位置、旋转和缩放。可以在Hierarchy面板查看层次关系。他们也支持计数器(enumerator),因此你可以使用循环遍历子物体。
C#
JavaScript
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
foreach (Transform child in transform) {
child.position += Vector3.up * 10.0F;
}
}
}
// Moves all transform children 10 units upwards!
//向上移动所有变换的子物体10个单位
for (var child : Transform in transform) {
child.position += Vector3.up * 10.0;
}
参见:Physics 类.
Variables变量
position
The position of the transform in world space.
在世界空间坐标transform的位置。
localPosition
Position of the transform relative to the parent transform.
相对于父级的变换的位置。
eulerAngles
The rotation as Euler angles in degrees.
旋转作为欧拉角度。
localEulerAngles
The rotation as Euler angles in degrees relative to the parent transform's rotation.
旋转作为欧拉角度,相对于父级的变换旋转角度。
right
The red axis of the transform in world space.
在世界空间坐标变换的红色轴。也就是x轴。
up
The green axis of the transform in world space.
在世界空间坐标变换的绿色轴。也就是y轴。
forward
The blue axis of the transform in world space.
在世界空间坐标变换的蓝色轴。也就是z轴。
rotation
The rotation of the transform in world space stored as a Quaternion.
在世界空间坐标物体变换的旋转角度作为Quaternion储存。
localRotation
The rotation of the transform relative to the parent transform's rotation.
物体变换的旋转角度相对于父级的物体变换的旋转角度。
localScale
The scale of the transform relative to the parent.
相对于父级物体变换的缩放。
parent
The parent of the transform.
物体变换的父级。
worldToLocalMatrix
Matrix that transforms a point from world space into local space (Read Only).
矩阵变换的点从世界坐标转为自身坐标(只读)。
localToWorldMatrix
Matrix that transforms a point from local space into world space (Read Only).
矩阵变换的点从自身坐标转为世界坐标(只读)。
root
Returns the topmost transform in the hierarchy.
返回层次最高的变换。
childCount
The number of children the Transform has.
变换的子物体数量。
lossyScale
The global scale of the object (Read Only).
物体的全局缩放(只读)。
Functions函数
Translate
Moves the transform in the direction and distance of translation.
移动transform在translation的方向和距离。
Rotate
Applies a rotation of eulerAngles.z degrees around the z axis, eulerAngles.x degrees around the x axis, and eulerAngles.y degrees around the y axis (in that order).