Skip to content

Transform

extends EngineObject

The Transform class records the position, rotation, and scale of an object. Every object in the scene has a Transform component. Each Transform can have a parent, which allows you to apply position, rotation, and scale hierarchically.

You can access the Transform component of an object in the following way:

typescript
OnStart(): void {
    // Get the Transform component of the current game object
    let transform = this.transform;
}

成员变量

Transform.instanceID : number
(Read Only) The instance ID of the object that this Transform belongs to.
Transform.up : Vector3
(Read Only) The unit vector in the positive Y direction of the game object's Transform in world space.
Transform.name : string
(Read Only) The name of the game object that the current Transform component is attached to.
Transform.childCount : number
(Read Only) The number of child transforms of the current Transform (excluding the parent Transform).
Transform.gameObject : GameObject
(Read Only) The game object that the current Transform component is attached to.
Transform.right : Vector3
(Read Only) The position of the game object's X-axis positive direction in world space Transform.
Transform.forward : Vector3
(Read Only) The unit vector in the positive Z direction in world space for the game object.
Transform.parent : Transform
The parent Transform of the current Transform.
Transform.localEulerAngles : Vector3
The rotation relative to the parent transform, expressed as Euler angles (in degrees).
Transform.localPosition : Vector3
The current position of the Transform relative to its parent Transform.
Transform.localScale : Vector3
The scale relative to the parent Transform.
Transform.localRotation : Quaternion
The rotation relative to the parent Transform.
Transform.eulerAngles : Vector3
(Read Only) The rotation of the game object as Euler angles in degrees.
Transform.position : Vector3
The current position of the Transform relative to the world.
Transform.lossyScale : Vector3
(Read Only) The global scale of the current Transform.
Transform.rotation : Quaternion
The quaternion representing the rotation of the current Transform in world space.
Transform.localToWorldMatrix : Matrix4x4
(Read Only) The matrix that transforms a point from local space to world space.
Transform.worldToLocalMatrix : Matrix4x4
(Read Only) The matrix that transforms points from world space to local space.
Transform.hasChanged : boolean
(Read Only) Whether the Transform has changed.

成员方法

Transform.GetChild ( index : number ) : Transform
Get the child Transform at the specified index (index starts from 0).
Transform.LookAt ( pos : Vector3 , up : Vector3? ) : void
Transform.GetPositionAndRotation ( ref_pos : Vector3 , ref_rot : Quaternion ) : void
Get the position and rotation of the Transform component in world space.
Transform.SetParent ( parent : Transform , keep_world_position : boolean? ) : void
Sets the parent object of the current Transform.
Transform.FindChild ( name : string ) : Transform
Find the child Transform of the current Transform attached to the game object by its name.
Transform.SetLocalTR ( pos : Vector3 , rot : Quaternion ) : void
Sets the local position and local rotation of an object relative to its parent object.
Transform.SetLocalTRS ( pos : Vector3 , rot : Quaternion , scale : Vector3 ) : void
Sets the local position, rotation, and scale information of an object relative to its parent Transform.
Transform.SetPositionAndRotation ( pos : Vector3 , rot : Quaternion ) : void
Sets the position and rotation of the current Transform component in world space.
Transform.TransformVector ( vector : Vector3 ) : Vector3
Transforms a vector from local space to world space.
Transform.TransformPoint ( point : Vector3 ) : Vector3
Converts a position from local space to world space (the returned position is affected by scale).
Transform.toString ( ) : string
The name of the object.
Transform.InverseTransformVector ( vector : Vector3 ) : Vector3
Converts a vector from world space to local space.
Transform.InverseTransformPoint ( point : Vector3 ) : Vector3
Converts a position from world space to local space.
Transform.InverseTransformPointAndRotation ( ref_point : Vector3 , ref_rot : Quaternion ) : void
Converts a position and rotation from world space to local space.