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 DibonaJ · Apr 28, 2011 at 07:40 PM · guiraycastingselection

GUI button vanishes when I release mouse button

Hi all. I'm having some GUI button issues. I have a piece of code right now for when you select some objects a test question comes up, telling you to select a specific object. After you select that object I want a GUI button to pop up that says either correct or incorrect. For the most part I have it, only when I release the mouse button the GUI button disappears. I have tried different combos of GetMouseButton, GetMouseButtonDown, and GetMouseButtonUp. But when I use GetMouseButtonDown in place of GetMouseButton the GUI button doesn't even show up at all. My code follows:

if(allObjectsClicked) { if(isClicked == false) { GUI.Box (new Rect (350,10,350,120), "Please click the learning cube."); { if (Input.GetMouseButton(1)) { if (Physics.Raycast (ray, out hit)) { if(hit.collider.gameObject.name == "learningCube2" || hit.collider.gameObject.name == "learningCylinder2") { isClicked = true; } } } } }

     if(isClicked)
     {
         if (Input.GetMouseButton(1))
         {
             if (Physics.Raycast (ray, out hit))
             {
                 if(hit.collider.gameObject.name == "learningCube2")
                 {
                     if(GUI.Button(new Rect (350, 10, 350, 120), "That was correct. You may now continue."))
                     {
                         navButtonEnabled = true;
                         Debug.Log("Why isn't the GUI button staying, jerk?");
                     }
                 }

                 else
                 {
                     GUI.Box(new Rect (350, 10, 350, 120), "Sorry, the correct answer was the cube. Click to advance.");
                     Debug.Log("Why isn't the GUI box staying part II");
                     navButtonEnabled = true;
                 }
             }
         }
     }
 }

Comment
Add comment · Show 1
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 DibonaJ · Apr 28, 2011 at 07:43 PM 0
Share

Note: This is being called in the onGUI function

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Apr 28, 2011 at 08:10 PM

if (Input.GetMouseButton(1)) is true only while the mouse button is held down. As soon as you release it, those buttons won't be 'called' to draw themselves. I think maybe if you just remove that from after the isClicked test it might behave for you

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 DibonaJ · Apr 28, 2011 at 08:16 PM 0
Share

I had to get rid of the if(Input...) and the if(Physics...) otherwise whatever my mouse was hovering over was being selected. Getting rid of both of them caused everything to work perfectly though. Thank you so much.

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

No one has followed this question yet.

Related Questions

Impossible: 2 toolbars show being clicked at the same time! 1 Answer

A 2D GUI in mid air, for oculus, tracking an object. 1 Answer

Selection box - drawing corner issue. 1 Answer

Raycasting and GUI 0 Answers

GUI Button vs RayCasting as input for random animation. 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