- Home /
GUI Buttons and game objects?
Is it possible to drag a game Object into or onto a GUI button which the GUI buttons act as a grid for an example? And the game object locks onto the GUI button like the drag and drop functionality in flash?
Answer by Jesse Anders · Jan 19, 2011 at 09:23 PM
Sure it's possible. (Game objects and GUI controls reside in different spaces, so you'll need to define specifically what the desired behavior is, but yes, whatever it is you're wanting to do, it's possible.)
I am having trouble trying to relate the GUI buttons with the game objects. I have a grid of 25 x 14 buttons which i need to drag and drop game objects in. I have the objects dragging and going back to its original position but i need them to stick to where the buttons are. Any suggestions?
Here's a hint: Check out the various Camera functions, such as WorldToScreenPoint() and ScreenToWorldPoint(). (These will help you get the positions of the in-game objects and the GUI controls into the same space.)
$$anonymous$$y thing is i know how to get the position of the gameobject, but how do i get the position of a grid of buttons that each have there own position using the Worldtoscreenpoint() and ScreenToworldPoint()? Please can you give me a way to implement this?
$$anonymous$$aybe someone else will provide a more detailed reply, but in short, if you use the GUI functions and specify the rects for the controls, then you already know where they are in screen space. You can then use WorldToScreenPoint() to get the object position into screen/GUI space (you might have to subtract the y value from the screen height - I can't remember for sure), and check to see if the point is in any of the control rectangles.