Description
The LocalPosition
property of a GameObject
represents its position relative to its parent object. If the GameObject
does not have a parent, the local position is relative to the scene's origin. This property is useful for positioning objects in a hierarchical structure, allowing for transformations that are relative to a parent object.
Usage
To get or set the local position of a GameObject
, you can use the LocalPosition
property. This property is of type Vector3
, which means it contains three components: X, Y, and Z, representing the position in 3D space.
Example usage:
- To retrieve the local position:
Vector3 currentPosition = myGameObject.LocalPosition;
- To set a new local position:
myGameObject.LocalPosition = new Vector3(1.0f, 2.0f, 3.0f);
Example
// Example of setting and getting the LocalPosition of a GameObject
// Assume 'myGameObject' is an instance of GameObject
// Set the local position to (1, 2, 3)
myGameObject.LocalPosition = new Vector3(1.0f, 2.0f, 3.0f);
// Get the current local position
Vector3 currentPosition = myGameObject.LocalPosition;
// Output the current local position
// Note: Avoid using Console.WriteLine in Sandbox environment
// Instead, use appropriate logging or debugging tools
// Debug.Log(currentPosition);