title: Check if UI elements/RectTransform are overlapping
body: <p>I'd like to know how I check whether two UI Panels on my Unity Canvas are overlapping each other.</p>
  
  <p>Currently I am doing this by comparing the canvas elements Rects</p>
  
  <p><strong>Canvas Settings</strong></p>
  
  <ul>
  <li>Render Mode: Screen Space - Camera</li>
  <li>Pixel Perfect: [Yes]</li>
  <li>Render Camera: Main Camera</li>
  <li>Plane Distance: 100</li>
  <li>Sorting Layer: Default</li>
  <li>Order In Layer: 0</li>
  </ul>
  
  <p><strong>Canvas Scaler Settings</strong></p>
  
  <ul>
  <li>UI Scale Mode: Constant Pixel Size</li>
  <li>Scale Factor: 1</li>
  <li>Reference Pixels Per Unit: 100</li>
  </ul>
  
  <p><strong>Code I am using to check</strong></p>
  
  <pre><code>[Header("Check For Overlap")]
  public RectTransform PlayerBar;
  public RectTransform LeftBar;
  public Rect RectOne;
  public Rect RectTwo;
  public bool overlapping;
  
  //Check if the two canvas element Rects overlap each other
  
  public void CheckForOverlap()
  {
      overlapping = false;
      // Convert Canvas RectTransforms to World Rects
      RectOne = GetWorldRect(LeftBar);
      RectTwo = GetWorldRect(PlayerBar);
  
      if (RectOne.Overlaps(RectTwo))
      {
          overlapping = true;
      }
  }
  
  
  public Rect GetWorldRect(RectTransform rt)
  {
      //  Get World corners, take top left
      Vector3[] corners = new Vector3[4];
      rt.GetWorldCorners(corners);
      Vector3 topLeft = corners[0];
  
      // Rect Size ... I'm not sure if this is working correctly?
      Vector2 size = new Vector2(rt.rect.size.x, rt.rect.size.y);
      return new Rect(topLeft, size);
  }
  </code></pre>
  
  <p><strong>What happens</strong></p>
  
  <p>'Overlapping' bool instantly changes to true.</p>
  
  <p>The Rect One returns as (example)</p>
  
  <p>X -7.5, Y 2.5
  W 98.5, H 164.1667</p>