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 26, 2011 at 03:43 PM · guigameobjectraycastselection

GUI Box not showing up after object clicked

Hello all. I am working on a project that requires the use to select a couple of objects, then once those objects are selected a test question shows up. The question then asks the user to select one of the objects to be able to continue.

All of that works right now, but the problem occurs when the object is clicked. I want a GUI Box to appear letting the user know if he clicked on the right object or not. After that a set of navigation buttons become available and the user can continue. The code is am using is:

if(allObjectsClicked && isClicked ==false) { GUI.Box (new Rect (350,10,350,120), "Please RIGHT click the learning cube."); { if (Input.GetMouseButtonDown(1)) { if (Physics.Raycast (ray, out hit)) { if(hit.collider.gameObject.name == "learningCube2") { isClicked = true; if(isClicked) { GUI.Box(new Rect (350,10,350,120), "Correct, you may now advance."); navButtonEnabled = true; Debug.Log("Why aren't you making the GUI box?"); } }

                     else
                     {
                         isClicked = true;
                         if(isClicked)
                         {
                             GUI.Box(new Rect (350, 10, 350, 120), "Sorry, the correct answer was the cube. Click to advance.");
                             Debug.Log("Why are you still not making the GUI box?");
                             navButtonEnabled = true;
                         }//end isClicked
                     }//end else
                 }//end raycast hit
             }//end getmousebuttondown
         }//end GUI box
     }//end allObjectsClicked
 }//end popUpDisplayed

}//end testQuestionThree /**/

The problem is that the "Correct" or "Sorry" boxes aren't showing up, but it is printing to the debug log and the nav buttons are becoming available again. Everything runs without errors, just those two boxes won't show up.

Comment
Add comment · Show 5
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 Joshua · Apr 26, 2011 at 03:53 PM 0
Share

Where are you calling this from? eg Start/Update/OnGUI. Have you tried using GUILayout to see if that works? Then you could check if gui is made but the problem is the box's rect.

avatar image DibonaJ · Apr 26, 2011 at 04:23 PM 0
Share

It is being called from OnGUI. I have never done anything with GUILayout before, so I will have to read up on that.

avatar image DibonaJ · Apr 26, 2011 at 04:40 PM 0
Share

O$$anonymous$$, I tried GUILayout and it didn't work either. I should have noted that I moved the GUI Box code somewhere else where I knew it would show up to make sure that it was written right and it worked.

avatar image DibonaJ · Apr 28, 2011 at 03:45 PM 0
Share

Another note. If I turn the boxes that aren't showing up into if buttons and put the enable nav buttons and debug log in there then they won't show up, as I haven't clicked the button. However, the button does not show up so I can't click it. I have tried what I have there, getting rid of isClicked all together, just getting rid of the isClicked == false in the if condition. I can't think of anything else to try.

avatar image sandhillceltic · Nov 28, 2013 at 03:22 AM 0
Share

Another thing, Ins$$anonymous$$d of having an excessive number of If's within If's (Ifception!!) try using &&, so if(condition1 && condition2 && condition3) { dothis }

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kourosh · Apr 26, 2011 at 04:01 PM

That's because you've set conditions under which your box will appear. When you click the isClicked boolean will be true and does not match your "if" condition anymore, which requires to have the isClicked false in order to run through the block.

Comment
Add comment · Show 3 · 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 26, 2011 at 04:25 PM 0
Share

It works pretty much the same with or without the isClicked. The only difference is that when I do have isClicked the first GUI box disappears, which is something I would like to happen. But when I take isClicked out of the code then the line is still written to the Debug Log, the nav buttons are still enabled, but the first GUI box remains and the second is never shown. I don't know if it is being built and is only there for a split second until onGUI is called again or not though.

avatar image Alec-Slayden · May 06, 2011 at 08:02 AM 0
Share

It's true that with this nesting, unless isClicked is set to false again elsewhere, that box is only going to be drawn for that onGUI call. GUI elements including boxes require constant calls to draw. If a box is being drawn, then it's being drawn from outside of that script, or your game is being paused, because it looks like as soon as isClicked is false, that whole script is ignored, returning false to the condition within which everything is nested.

avatar image Alec-Slayden · May 06, 2011 at 08:02 AM 0
Share

**as soon as isClicked is true, that should say

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

1 Person is following this question.

avatar image

Related Questions

Char select / GUI button question. 3 Answers

I am getting an error and cant figure out why, Help please? 1 Answer

GameObject GUI? 0 Answers

Advance when the sound is done playing 1 Answer

Get texture from gui to gameobject 1 Answer


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