Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ruben · May 13, 2010 at 08:59 AM · switch

Switching GUI on and off

hi

i normally use a bool value to swicth my windows on and off, does anyone know of another way to switch them on and off?

the script i use:

function OnGUI() { if (windowOpen) { GUI.skin = mySkin; OrbInstantiate.freezed = true; windowRect = GUILayout.Window(0,windowRect,DoMyWindow,"Orb Info");

     if (addComment) 
     {
        windowComment = GUI.Window(0,windowComment,CommentWindow,"Orb Info");
     }

thanks!

Comment
Add comment · Show 2
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 Eric5h5 · May 13, 2010 at 09:18 AM 0
Share

Format code by selecting it and hitting the code button.

avatar image Ruben · May 13, 2010 at 09:21 AM 0
Share

ok thanks did'nt know that

2 Replies

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

Answer by Ashkan_gc · May 13, 2010 at 09:49 AM

you can use bool values as you said. you can make the gameobject that has the gui active/inactive too. use the active property. also you can enable/disable the component that has the gui with enabled property. the unity GUI system is a low level system. you can create classes for GUI and expose properties like visible for them and use things like this

if (visible == true)
{
//call the GUI method like GUI.Button ()
}

also you can expose other properties like letf/top and width/height and value and ... a GUI Element class would look like

class GUIElement
{
public bool visible;
public float left,top,width,height;
public string name;
GUIElement (string s)
{
name = s;
}
virtual Draw ()
}

then you should have a form class that you add other elements to it and it will call the draw method of all gui elements inside it in it's onGUI

class form : MonoBehaviour { private List elements = new List();

void OnGUI () { foreach (GUIElement g in elements) { g.Draw(); } } } then you should define classes for Button and TextField and ... that they are children of GUIElement and define their own Draw methods that use the properties to draw the control a draw method for a button would use a GUI command like this

if (GUI.Button (new Rect(left,top,width,height),name))
{
}

you can have a deligate to call when this happens and also form class can have methods for creating a button and label and adding the created element to the list

you can create XML file structures to read and create GUI based on them and many more

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 Ruben · May 13, 2010 at 10:46 AM 0
Share

ok the prob i'm having is:

i have multiple gameobjects that instantiates at runtime. each object gets assigned an id and has a GUI/window script on it. when i click on an object i want it to display the current id for the object. but now its displaying the last id that was assigned to the last gameobject that got instantiated. how do i go about getting this right?

avatar image Ashkan_gc · May 13, 2010 at 05:53 PM 0
Share

use a static variable in a class and put the id of the clicked object in the static var and show that var.

avatar image meat5000 ♦ · Oct 21, 2013 at 08:48 AM 0
Share

Is this answer correct/still relevant? As far as I know OnGUI and GUIElement are two different GUI systems. Correct me if I'm wrong.

avatar image
5

Answer by Eric5h5 · May 13, 2010 at 09:19 AM

You can disable and enable the script that has the OnGUI function.

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 Ruben · May 14, 2010 at 07:17 AM 0
Share

do you perhaps have a sample code for me?

avatar image Eric5h5 · May 14, 2010 at 04:39 PM 0
Share

@Ruben: "`GetComponent(NameOfScriptWithGUIFunction).enabled = false;`" Or true to enable.

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

weapon switching 1 Answer

Switching weapons/tools using a GameObject array 2 Answers

switch scripts? 1 Answer

GUI Script switching on and off. 1 Answer

gun switch script 26-feb-2010 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