Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetWorldCorners

Get the corners of the calculated rectangle in world space.
Read time 2 minutesLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

GetWorldCorners(Vector3[])

Get the corners of the calculated rectangle in world space.
public void GetWorldCorners(Vector3[] fourCornersArray)

Parameters

fourCornersArray

The array that corners are filled into.

Remarks

Each corner provides its world space value. The returned array of 4 vertices is clockwise. It starts bottom left and rotates to top left, then top right, and finally bottom right. Note that bottom left, for example, is an (x, y, z) vector with x being left and y being bottom.
Note: If the RectTransform is rotated in Z then the dimensions of the RectTransform.GetWorldCorners will be changed.
using UnityEngine;// GetWorldCorners():// Access the RectTransform and read the vertices// that define the location and size of the// object.public class ExampleClass : MonoBehaviour{ RectTransform rt; void Start() { rt = GetComponent<RectTransform>(); DisplayWorldCorners(); } void DisplayWorldCorners() { Vector3[] v = new Vector3[4]; rt.GetWorldCorners(v); Debug.Log("World Corners"); for (var i = 0; i < 4; i++) { Debug.Log("World Corner " + i + " : " + v[i]); } }}
Additional Resources: RectTransform.GetLocalCorners.

GetWorldCorners(Span<Vector3>)

Get the corners of the calculated rectangle in world space.
public void GetWorldCorners(Span<Vector3> fourCorners)

Parameters

fourCorners

Remarks

Each corner provides its world space value. The returned array of 4 vertices is clockwise. It starts bottom left and rotates to top left, then top right, and finally bottom right. Note that bottom left, for example, is an (x, y, z) vector with x being left and y being bottom.
Note: If the RectTransform is rotated in Z then the dimensions of the RectTransform.GetWorldCorners will be changed.
using UnityEngine;// GetWorldCorners():// Access the RectTransform and read the vertices// that define the location and size of the// object.public class ExampleClass : MonoBehaviour{ RectTransform rt; void Start() { rt = GetComponent<RectTransform>(); DisplayWorldCorners(); } void DisplayWorldCorners() { Vector3[] v = new Vector3[4]; rt.GetWorldCorners(v); Debug.Log("World Corners"); for (var i = 0; i < 4; i++) { Debug.Log("World Corner " + i + " : " + v[i]); } }}
Additional Resources: RectTransform.GetLocalCorners.