Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

RectTransform

class in UnityEngine

/

Inherits from: Transform

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

Sumbission failed

For some reason your suggested change could not be submitted. Please try again 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, size, anchor and pivot information for a rectangle.

RectTransforms are used for GUI but can also be used for other things. It's used to store and manipulate the position, size, and anchoring of a rectangle and supports various forms of scaling based on a parent RectTransform.

Variables

anchoredPositionThe position of the pivot of this RectTransform relative to the anchor reference point.
anchoredPosition3DThe 3D position of the pivot of this RectTransform relative to the anchor reference point.
anchorMaxThe normalized position in the parent RectTransform that the upper right corner is anchored to.
anchorMinThe normalized position in the parent RectTransform that the lower left corner is anchored to.
offsetMaxThe offset of the upper right corner of the rectangle relative to the upper right anchor.
offsetMinThe offset of the lower left corner of the rectangle relative to the lower left anchor.
pivotThe normalized position in this RectTransform that it rotates around.
rectThe calculated rectangle in the local space of the Transform.
sizeDeltaThe size of this RectTransform relative to the distances between the anchors.

Public Functions

GetLocalCornersGet the corners of the calculated rectangle in the local space of its Transform.
GetWorldCornersGet the corners of the calculated rectangle in world space.
SetInsetAndSizeFromParentEdgeSet the distance of this rectangle relative to a specified edge of the parent rectangle, while also setting its size.
SetSizeWithCurrentAnchorsMakes the RectTransform calculated rect be a given size on the specified axis.

Events

reapplyDrivenPropertiesEvent that is invoked for RectTransforms that need to have their driven properties reapplied.

Delegates

ReapplyDrivenPropertiesDelegate used for the reapplyDrivenProperties event.

Inherited members

Variables

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 (null if there is none attached).
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.
childCountThe number of children the 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 parent transform's rotation.
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 position of the transform in world space.
rightThe red axis of the transform in world space.
rootReturns the topmost transform in the hierarchy.
rotationThe rotation of the transform in world space stored as a Quaternion.
upThe green axis of the transform in world space.
worldToLocalMatrixMatrix that transforms a point from world space into local space (Read Only).

Public Functions

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 game object.
DetachChildrenUnparents all children.
FindFinds a child by name 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.
RotateApplies 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).
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.
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.

Static Functions

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately.
DontDestroyOnLoadMakes the object target not be destroyed automatically 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.
InstantiateReturns a copy of the object original.

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.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961