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 ric_eng · Sep 02, 2010 at 11:37 AM · guirenderrefresh

gui refresh render

Hi,I have two situations and for each a GUI. A variable controls whether a button will show text only or with only a icon button.

var imageText : boolean = true;

//button that control if(GUI.Button (Rect (10, 210, 100, 15), "IMAGE OU TEXT")) { imageText = !imageText; }

if(imageText == true) { if (GUI.Button (Rect (5, 100, 50, 50), icon)) { }
}else{

  if (GUI.Button (Rect (5, k, 50, 50), text)) {
    }

}

the problem is that I even turning the button("IMAGE OU TEXT") and the control variable being altered my render no change of icon to text.

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

Answer by diabloroxx · Sep 02, 2010 at 09:15 PM

I just tested out your code. The problem occurs because as soon as OnGUI() is called, it looks at the Boolean value and immediately prints the GUI Button. So in effect there are 3 Gui Buttons being loaded. So the one with Icon is always loaded first. I modified the code where you actually check whether it is ready to load the GUI. Hope it helps.

var imageText : boolean = true; var icon : Texture2D; var readytoload = 0;

//button that control function OnGUI(){

if(GUI.Button (Rect (10, 210, 100, 15), "IMAGE OR TEXT")) { readytoload = 1; imageText = !imageText; Debug.Log(imageText); }

if(readytoload) { if(imageText) if (GUI.Button (Rect (5, 100, 50, 50), icon)) { imageText = true; Debug.Log("Icon"); Debug.Log(imageText); }

if(!imageText) { if (GUI.Button (Rect (205,100, 50, 50), "Text")) { imageText = false; Debug.Log("Text"); Debug.Log(imageText); } } } }

Comment
Add comment · Show 2 · 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 ric_eng · Sep 02, 2010 at 11:40 PM 0
Share

I did not understand well. a simple X causes a delay in the GUI. is it? Because the readytoload value not change

avatar image diabloroxx · Sep 07, 2010 at 03:29 PM 0
Share

No it is not about the delay. Initially when OnGUI() is called, it automatically renders the GUI with Icon as the default value of imageText is true. When we change the condition of the imageText to (false), then the GUI-Text is rendered. Again when the condition is changed, (imagetext is set to True) the GUI Icon is rendered ins$$anonymous$$d of the currently created GUI Text. So in essence there are 3 GUI buttons. 1. The one which is initially created. 2. The GUI Text button. 3. GUI Icon button.

The only work around is to check if you need one GUI Button as soon as the OnGUI is loaded.

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

Drawing a GUI.DrawTexture call above GUI.Button in seperate scripts 0 Answers

Can i render a camera to a gui texture? 1 Answer

How should I generate an image of a model? 1 Answer

how to render line between gui element and mouse position 1 Answer

What GUI method renders 3D object thumbnail previews in the editor? 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