• 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 Rgalaxy · Jan 19, 2014 at 06:55 AM · javascriptguigui-buttonpop-up

[Solved]The Right way of doing PopUp

Holla ! i want to ask if what i do is aldy the right way of doing a popup? i've been looking about popup for a while and found out this was right, but, i have a problem where, the Gui.button couldn't click.. but GUI on the back of this one can clicked..

here is the image of what i mean. alt text see that blue box behind is the GUI behind it, if i click it, the brown box popup ! but now if i want to press the red x button, i the button won't click.. but i can only click the button behind them.. is there any way to prevent this to happen? or does my way of popingup is wrong?

here's my code for the entire GUI, it's not much, so i will print all :)

 #pragma strict
 var buttonHealth : GUIStyle;
 var buttonAttack : GUIStyle;
 var buttonReward : GUIStyle;
 var buttonTime : GUIStyle;
 var popUp1: Texture;
 var ispopUp : boolean;
 var buttonOK : GUIStyle;
 var buttonCancel : GUIStyle;
 function Start () {
 
 }
 function OnGUI(){
     if(GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.1,Screen.width*0.4,Screen.height*0.2)," ",buttonHealth)){
         print("a");
         ispopUp=true;
         print("b");
     }
     
     GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.4,Screen.height*0.2)," ",buttonAttack);
     GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.5,Screen.width*0.4,Screen.height*0.2)," ",buttonReward);
     GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.7,Screen.width*0.4,Screen.height*0.2)," ",buttonTime);
     if(ispopUp){
         GUI.DrawTexture(Rect(Screen.width*0.3,Screen.height*0.3,Screen.width*0.5,Screen.height*0.5),popUp1);
         GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.1,Screen.height*0.1)," ",buttonCancel);
     }
 }

capture.png (315.8 kB)
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
1
Best Answer

Answer by xt-xylophone · Jan 20, 2014 at 02:31 AM

Your code for the button is not doing anything aside from drawing the button. Try:

 if(GUI.Button(new Rect(Screen.width*0.5,Screen.height*0.3,Screen.width*0.1,Screen.height*0.1)," ",buttonCancel)) {
     ispopUp=false;
 }

You never said that the cancel button actually did some cancel logic

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 Rgalaxy · Jan 21, 2014 at 06:40 PM 0
Share

@xt.xylophone yeah.. i added it, but that's not the problem, the problem is, i couldn't able to click it(touch) the red button there, but, the one that get clicked is the blue button behind the red one.. it's so irritating when i couldn't just set the layer of GUI, i mean maybe after it popup, i want so the back blue thing will not able to clicked.. is there any way to achieve this?

avatar image xt-xylophone · Jan 21, 2014 at 10:35 PM 0
Share

In the if statement for that blue button you could put

 && !ispopUp

This means the button will not work as long as ispopUp is true

avatar image Rgalaxy · Jan 21, 2014 at 11:48 PM 1
Share

thanks xylophone :D

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

make key as a button 1 Answer

Move the text in a GUI Button/Box 1 Answer

help with errors 2 Answers

Setting Scroll View Width GUILayout 1 Answer

[Solved]GUI won't pop out 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