对象的位置、旋转和缩放。
场景中的每个对象都有一个变换。 它用于存储和操作对象的位置、旋转和缩放。 每个变换都可以有一个父级,让您能够分层应用位置、旋转和缩放。这是“Hierarchy”面板中显示的层级视图。 它们还支持枚举器,因此您可以使用以下方式遍历子项:
using UnityEngine;
public class Example : MonoBehaviour { // Moves all transform children 10 units upwards! void Start() { foreach (Transform child in transform) { child.position += Vector3.up * 10.0f; } } }
childCount | 父变换具有的子项数。 |
eulerAngles | 以欧拉角表示的旋转(以度为单位)。 |
forward | 返回一个标准化矢量,它表示世界空间中变换的蓝轴。 |
hasChanged | 自上次将标志设置为“false”以来,变换是否发生更改? |
hierarchyCapacity | 变换的层级视图数据结构的变换容量。 |
hierarchyCount | 变换的层级视图数据结构中变换的数量。 |
localEulerAngles | 以欧拉角表示的相对于父变换旋转的旋转(以度为单位)。 |
localPosition | 相对于父变换的变换位置。 |
localRotation | 相对于父级变换旋转的变换旋转。 |
localScale | 相对于 GameObjects 父对象的变换缩放。 |
localToWorldMatrix | 将点从本地空间转换到世界空间的矩阵(只读)。 |
lossyScale | 对象的全局缩放。(只读) |
parent | 变换的父级。 |
position | 世界空间中的变换位置。 |
right | 世界空间中变换的红轴。 |
root | 返回层级视图中最顶层的变换。 |
rotation | 一个 Quaternion,用于存储变换在世界空间中的旋转。 |
up | 世界空间中变换的绿轴。 |
worldToLocalMatrix | 将点从世界空间转换到本地空间的矩阵(只读)。 |
DetachChildren | 清除所有子项的父级。 |
Find | Finds a child by name n and returns it. |
GetChild | 按索引返回变换子项。 |
GetLocalPositionAndRotation | Gets the position and rotation of the Transform component in local space (that is, relative to its parent transform). |
GetPositionAndRotation | Gets the position and rotation of the Transform component in world space. |
GetSiblingIndex | 获取同级索引。 |
InverseTransformDirection | Transforms a direction from world space to local space. The opposite of Transform.TransformDirection. |
InverseTransformDirections | Transforms multiple directions from world space to local space overwriting each original position with the transformed version. The opposite of Transform.TransformDirections. |
InverseTransformPoint | 将 position 从世界空间变换到本地空间。 |
InverseTransformPoints | Transforms multiple positions from world space to local space overwriting each original position with the transformed version. |
InverseTransformVector | Transforms a vector from world space to local space. The opposite of Transform.TransformVector. |
InverseTransformVectors | Transforms multiple vectors from world space to local space overwriting each original position with the transformed version. The opposite of Transform.TransformVectors. |
IsChildOf | 该变换是否为 parent 的子项? |
LookAt | 旋转变换,使向前矢量指向 target 的当前位置。 |
Rotate | 使用 Transform.Rotate 以各种方式旋转 GameObjects。通常以欧拉角而不是四元数提供旋转。 |
RotateAround | 将变换围绕穿过世界坐标中的 point 的 axis 旋转 angle 度。 |
SetAsFirstSibling | 将变换移动到本地变换列表的开头。 |
SetAsLastSibling | 将变换移动到本地变换列表的末尾。 |
SetLocalPositionAndRotation | Sets the position and rotation of the Transform component in local space (i.e. relative to its parent transform). |
SetParent | 设置变换的父级。 |
SetPositionAndRotation | 设置变换组件的世界空间位置和旋转。 |
SetSiblingIndex | 设置同级索引。 |
TransformDirection | 将 direction 从本地空间变换到世界空间。 |
TransformDirections | Transforms multiple directions from local space to world space overwriting each original direction with the transformed version. |
TransformPoint | 将 position 从本地空间变换到世界空间。 |
TransformPoints | Transforms multiple points from local space to world space overwriting each original point with the transformed version. |
TransformVector | 将 vector 从本地空间变换到世界空间。 |
TransformVectors | Transforms multiple vectors from local space to world space overwriting each original vector with the transformed version. |
Translate | 根据 translation 的方向和距离移动变换。 |
gameObject | 此组件附加到的游戏对象。始终将组件附加到游戏对象。 |
tag | 此游戏对象的标签。 |
transform | 附加到此 GameObject 的 Transform。 |
hideFlags | 该对象应该隐藏、随场景一起保存还是由用户修改? |
name | 对象的名称。 |
BroadcastMessage | 调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。 |
CompareTag | Checks the GameObject's tag against the defined tag. |
GetComponent | Gets a reference to a component of type T on the same GameObject as the component specified. |
GetComponentInChildren | Gets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject. |
GetComponentInParent | Gets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject. |
GetComponents | Gets references to all components of type T on the same GameObject as the component specified. |
GetComponentsInChildren | Gets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject. |
GetComponentsInParent | Gets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject. |
SendMessage | 调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。 |
SendMessageUpwards | 调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。 |
TryGetComponent | 获取指定类型的组件(如果存在)。 |
GetInstanceID | Gets the instance ID of the object. |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
FindObjectsOfType | Gets a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.