Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created February 18, 2016 13:33
Show Gist options
  • Save unitycoder/5fd13202d3e719a3736f to your computer and use it in GitHub Desktop.
Save unitycoder/5fd13202d3e719a3736f to your computer and use it in GitHub Desktop.
Check if 2 UI Elements are overlapping (using Rect.Overlaps())
Vector3[] corners = new Vector3[4];
rectTransform1.GetWorldCorners(corners);
Rect rec = new Rect(corners[0].x,corners[0].y,corners[2].x-corners[0].x,corners[2].y-corners[0].y);
rectTransform2.GetWorldCorners(corners);
Rect rec2 = new Rect(corners[0].x, corners[0].y,corners[2].x-corners[0].x,corners[2].y-corners[0].y);
if (rectTransform1.Overlaps(rectTransform2))
{
Debug.Log("rectTransform1 is Overlapping rectTransform2!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment