- Home /
The question is answered, right answer was accepted
GUI 2D Bounding Box
I saw this GUI bounding box while I am looking at the HOTween's documentation page.
I know how to control the Texture2D position and size using script but I cannot figure out how can I access the 2D box data from a 3D object. Furthermore, the bounding box in the right are reacting to multiple objects.
This is the page I saw the GUI bound box.
I will be very glad if someone can point me at the right direction.
Answer by robertbu · Feb 24, 2013 at 03:45 PM
One method is to use Renderer.bounds. Take the corners of the enclosing space for each object and translate them to Viewport coordinates. Then figure out the minimum and maximum values.
So there is no straight forward method then?
From your technique, I should store the x-coordinate into one array and y-coordinate into another array. After sorting them, the 1st and last element will be the $$anonymous$$imum and maximum.
I think I can work with this solution. Too bad that there isn't any ready made function similar to Camera.WorldToScreenPoint
for creating a 2D boundary.
Putting them in an array and sorting them is one way, but you don't really need to sort them...just exa$$anonymous$$e each corner and compare to the current $$anonymous$$/max for x and y. Pretty ugly, but I cannot think of another way.
Putting them into an array and sort them is a shortcut move, I am kinda lazy to manually write the code segment to identify $$anonymous$$ and max for both x and y.