1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Unity] UIのワールド矩形領域を得る

Last updated at Posted at 2021-12-01

image.png

World座標系のオブジェクトがUI領域にあるかどうかを知りたい時などに、
RectTransform.GetWorldCorners(Vector3[4])
を使うと、UI(RectTransform)の4頂点を一気にとれる。
もちろん回転していても大丈夫。

void debugDrawMargin(RectTransform _marginRT)
{
    Vector3[] corners = new Vector3[4];
    _marginRT.GetWorldCorners(corners);
    Debug.DrawLine(corners[0], corners[1], Color.yellow);
    Debug.DrawLine(corners[1], corners[2], Color.yellow);
    Debug.DrawLine(corners[2], corners[3], Color.yellow);
    Debug.DrawLine(corners[3], corners[0], Color.yellow);
}
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?