GameTransform Transform { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The Transform property of a Component provides access to the GameTransform of the GameObject to which this component is attached. Components themselves do not have their own transforms; instead, they utilize the transform of their parent GameObject. This property serves as a convenient shortcut to GameObject.Transform.

Usage

Use the Transform property when you need to access or modify the position, rotation, or scale of the GameObject that a component is attached to. This property is read-only and provides a direct reference to the GameObject's transform, allowing you to perform operations such as translation, rotation, and scaling.

Example

// Example of accessing the Transform property in a component
public class MyComponent : Component
{
    public void MoveUp(float distance)
    {
        // Access the Transform property to move the GameObject upwards
        Transform.Position += Vector3.Up * distance;
    }
}