• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dreal · Jan 19, 2011 at 05:39 PM · gameobjectgrid2d-gameplaydrag-and-dropgui.button

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dreal · Jan 22, 2011 at 08:14 PM 0
Share

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?

avatar image Jesse Anders · Jan 23, 2011 at 08:51 AM 0
Share

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.)

avatar image dreal · Jan 27, 2011 at 07:05 AM 0
Share

$$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?

avatar image Jesse Anders · Jan 27, 2011 at 08:06 AM 0
Share

$$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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Mouse drag cloning Game Objects 1 Answer

How to apply more than one trigger on a single gamebject 1 Answer

when i add a gameobject it is way off grid? 1 Answer

Detect if UI element is over Gameobject 2 Answers

Snap Objects to Grid during Runtime with mouse 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges