GetPositionAndRotation(out Vector3, out Quaternion)
Updates the value of the out parameters position and rotation with the transform's current position and rotation in world space (that is, relative to the scene's origin coordinates).
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
GetPositionAndRotation(Vector3, Quaternion)
public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation)
Parameters
Out parameter that will receive the position of the transform in world space.
Out parameter that will receive the rotation of the transform in world space.
Remarks
Note: When getting both the and of a , calling this method is more efficient than querying to TransformHandle.position and TransformHandle.rotation individually.
positionrotationTransformHandleThe typical usage for this method is to retrieve a transform's and in world space, to either display them or evaluate them. For example:
positionrotation transformHandle.GetPositionAndRotation(out Vector3 position, out Quaternion rotation)The following example logs the position and rotation of a 's in world space.
GameObjectTransformHandleusing UnityEngine;// Attach this script to a GameObject as a component.public class GetPositionAndRotationExample : MonoBehaviour{ void Start() { // transformHandle refers to the <see cref="UnityEngine.TransformHandle"></see> of the <see cref="UnityEngine.GameObject"></see> this script is attached to. transformHandle.GetPositionAndRotation(out Vector3 position, out Quaternion rotation); // We will convert the rotation <see cref="UnityEngine.Quaternion"></see> to Euler angles for readability. Debug.Log($"{name} is located at {position}, and has the rotation {rotation.eulerAngles}"); }}
Additional Resources: Quaternion, Vector3.