The Transform.Add
method allows you to add a specified position to the current transform, either in local or world space. This method returns a new Transform
instance with the updated position.
The Transform.Add
method allows you to add a specified position to the current transform, either in local or world space. This method returns a new Transform
instance with the updated position.
To use the Add
method, you need to provide a Vector3
representing the position you want to add, and a bool
indicating whether the position should be added in world space or local space.
If worldSpace
is set to true
, the position will be added in world coordinates. If set to false
, the position will be added in local coordinates relative to the current transform.
// Example of using Transform.Add Transform currentTransform = new Transform(); Vector3 additionalPosition = new Vector3(1, 2, 3); bool useWorldSpace = true; // Add the position in world space Transform newTransform = currentTransform.Add(additionalPosition, useWorldSpace); // Output the new position Vector3 newPosition = newTransform.Position; // newPosition now contains the updated position based on the addition