Transform

class in UnityEngine

/

Inherits from:Component

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

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:

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; } } }

Properties

childCountThe number of children the parent Transform has.
eulerAnglesThe rotation as Euler angles in degrees.
forwardThe blue axis of the transform in world space.
hasChangedHas the transform changed since the last time the flag was set to 'false'?
hierarchyCapacityThe transform capacity of the transform's hierarchy data structure.
hierarchyCountThe number of transforms in the transform's hierarchy data structure.
localEulerAnglesThe rotation as Euler angles in degrees relative to the parent transform's rotation.
localPositionPosition of the transform relative to the parent transform.
localRotationThe rotation of the transform relative to the transform rotation of the parent.
localScaleThe scale of the transform relative to the parent.
localToWorldMatrixMatrix that transforms a point from local space into world space (Read Only).
lossyScaleThe global scale of the object (Read Only).
parentThe parent of the transform.
positionThe world space position of the Transform.
rightThe red axis of the transform in world space.
rootReturns the topmost transform in the hierarchy.
rotationA quaternion that stores the rotation of the Transform in world space.
upThe green axis of the transform in world space.
worldToLocalMatrixMatrix that transforms a point from world space into local space (Read Only).

Public Methods

DetachChildrenUnparents all children.
FindFinds a child by n and returns it.
GetChildReturns a transform child by index.
GetSiblingIndexGets the sibling index.
InverseTransformDirectionTransforms a direction from world space to local space. The opposite of Transform.TransformDirection.
InverseTransformPointTransforms position from world space to local space.
InverseTransformVectorTransforms a vector from world space to local space. The opposite of Transform.TransformVector.
IsChildOfIs this transform a child of parent?
LookAtRotates the transform so the forward vector points at /target/'s current position.
RotateUse Transform.Rotate to rotate GameObjects in a variety of ways. The rotation is often provided as a Euler angle and not a Quaternion.
RotateAroundRotates the transform about axis passing through point in world coordinates by angle degrees.
SetAsFirstSiblingMove the transform to the start of the local transform list.
SetAsLastSiblingMove the transform to the end of the local transform list.
SetParentSet the parent of the transform.
SetPositionAndRotationSets the world space position and rotation of the Transform component.
SetSiblingIndexSets the sibling index.
TransformDirectionTransforms direction from local space to world space.
TransformPointTransforms position from local space to world space.
TransformVectorTransforms vector from local space to world space.
TranslateMoves the transform in the direction and distance of translation.

Inherited Members

Properties

gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the GameObject.

Static Methods

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答