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 /
This question was closed Oct 30, 2013 at 07:40 PM by clunk47 for the following reason:

Duplicate Question

avatar image
0
Question by Jammer3000 · Oct 30, 2013 at 06:31 PM · guigui-button

How to create a gui button inside an if statement?

Hi I want to know if its possible to create a gui button outside of the OnGUI() function. Is it possible for the code below to work in another if statement? Outside of the OnGUI() function?

 if (GUI.Button(Rect(10,70,100,40),"Drop Ball")) 
         {
             attachedRigidbody = rigidbodyTrigger.rigidbody;
             attachedRigidbody.useGravity = true;
             //guiTrigger = true;
         }
Comment
Add comment · Show 4
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 memblock · Oct 30, 2013 at 06:46 PM 1
Share

why do you want a gui button outside of the OnGUI() function? I'm not sure if that is possible

avatar image Jammer3000 · Oct 30, 2013 at 07:36 PM 0
Share

Your right I really don't think its possible, I just got around it by making a public static var and then using it to store what I wanted in it and then using it and whats stored inside, inside of the OnGUI() function in order to get what I wanted. Thanks anyway!

avatar image clunk47 · Oct 30, 2013 at 07:39 PM 0
Share

$$anonymous$$aybe ins$$anonymous$$d of asking how to do this, tell us WHY exactly. Edit your question to ask WHAT YOU ARE TRYING TO DO OVERALL. This will work way better than posting the same question multiple times.

avatar image Jammer3000 · Oct 30, 2013 at 07:42 PM 0
Share

I know I wasn't trying to just get help, I was just wondering if anyone knew if it was possible or not or if they have done it before cause I've researched a bunch and couldn't find anything.

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by clunk47 · Oct 30, 2013 at 06:48 PM

NO. You can, however create the String for your label and Rect outside of GUI. If you only want to show your button under a certain condition, use a boolean.

 var showButton : boolean = false;
 var rect : Rect = new Rect(0, 0, 128, 128);
 var label : String = "Click Me";
  
 function Update()
 {
     if(Input.GetKeyDown(KeyCode.S))
     showButton = !showButton;
 }
  
 function OnGUI()
 {
     if(showButton)
     {
         if(GUI.Button(rect, label))
         {
             //YourCodeHere
         }
     }
 }

You can also create GUIContent outside of gui code...

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

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Turn off my GUI Box when I click a button. 3 Answers

How To Make GUI Buttons Load/Quit 1 Answer

What is frame, How OnGuI is called every frame? 2 Answers

'MouseLook.sensitivityX' is inaccessible due to its protection level. 2 Answers

What can i use besides an event current 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