Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 AnaF · Nov 14, 2011 at 01:12 AM · drag-and-dropgui.button

Problem with GUI.Button

Hi all, I'm starting with Unity and since yesteraday I have a problem that I can't resolve. I'm using GUI.Button to create 7 buttons, and I should be able to move this buttons with the mouse (like if this button was the piece of a puzzle). Can somebody explain me how to do that?

Thanks!! Ana

Comment
Add comment · Show 2
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 syclamoth · Nov 14, 2011 at 01:28 AM 0
Share

Do you want the buttons to also act like normal buttons? In any case, I can see a way to do it, but it's not nearly as straightforward as I think you think it is. $$anonymous$$ind if I answer in C#? I'm not very good at JS.

avatar image AnaF · Nov 14, 2011 at 01:37 PM 0
Share

The game that I'm trying to do have a set of 7 button that represent: move to front, move to left, move to right, jump, light, function1 and function2. The idea is that the user move this buttons and put them in order, so the sequence of steps represent the movement of a robot. $$anonymous$$y first intention is move this buttons around the screen, and another partner is working on the movements of the robot. I will appreciate your help! Thanks in advance!

Ana.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Hurricanes · Nov 14, 2011 at 09:19 PM

Do you really need these to be buttons ? I mean, a button is meant to be a clickable area on the screen. It seems what you want to do is just have 7 boxes displayed on the screen, which can be moved by the user in a certain order. If you don't need the "click" functionality of a button, you might want to use simple planes with a 2D texture to represent your 7 states.

Comment
Add comment · 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
0

Answer by cj_coimbra · Nov 14, 2011 at 03:14 PM

Try this:

     private Rect sampleButton = new Rect (100,100,80,25);
     private bool sampleButtonSelected = false;
     void OnGUI()
     {
         if (sampleButtonSelected)
         {
             sampleButton.x = Input.mousePosition.x - 40;
             sampleButton.y = Screen.height - Input.mousePosition.y - 10;
             if (GUI.Button(sampleButton, "Sample!"))
             {
                 sampleButtonSelected = !sampleButtonSelected;
                 //do something
             }
         }
         else
         {
             if (GUI.Button(sampleButton, "Sample!"))
             {
                 sampleButtonSelected = !sampleButtonSelected;
                 //do something
             }
         }
     }

This is just one button sample, but if you get the idea, you sure can reproduce it to the others...

Comment
Add comment · Show 1 · 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 AnaF · Nov 14, 2011 at 03:32 PM 0
Share

Thank you so much for the help!! I'm going to try this as soon as I get home! :)

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Buttons and game objects? 1 Answer

What method should I use for making a drag 'n drop based game? 1 Answer

How to change the game-window style? 0 Answers

Touch on GUI.Button HELP!!!! 3 Answers

Change GUILayout.Button fontsize 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges