I have a rectangle. It is necessary to determine the coordinates of its sides in the code (x - for the right and left, y - for the top and bottom). I know about some built-in functions bounds.extents. But this is not that. What to do?
- Game engine Unity3D. The rectangle has a Renderer. There are coordinates of the center. - Reodont
2 answers
You need to know the size of your rectangle. If the mesh type is Quad , then its localScale in x,y defines linear dimensions in world coordinates (initially, Quad 'a sides are equal to one).
Those.
width = transform.localScale.x // ширина height = transform.localScale.y // высота
Let (xc, yc) be the coordinates of the center.
xl = xc - width/2 //"левый" x xr = xc + width/2 //"правый" x
For y , it is the same (in the world coordinate system, the Oy axis goes from bottom to top).
yt = yc + height/2 //"верхний" y yb = yc - height/2 //"нижний" y
In this way,
(xc - width/2, yc + height/2) - левый верхний угол (xc + width/2, yc - height/2) - правый нижний
I hope, clearly explained :) For specificity, you need the type of your model.
If it is necessary purely out of interest, create an empty GameObject , hold down the V key and bring it to the desired side.