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 alpha-ro · Jun 15, 2013 at 06:44 PM · gameobjecttoggleenablebasics

How to basically use GUI.Toggle?

This has been killing me for days. You see, i'm trying to make an aceptable Pause Menu in wich i have already made a button that takes the user to an Options Screen, and in that options screen i want to have a variety of toggles that can be showed enabled and disabled (change the state they are showing), but the problem i don't know the basics of the GUI.Toggle as well as the GUILayout.Toggle (this is what i'm trying to use, i've already took a look at Scripting Reference...but the explanation is poor, only explains how to put text or an image, but nothing else).

I want, in this first case, to set a gameobject to enabled or disabled depending in a respective toggle (let's call it 'NevDensa'). The gameobject contains a Particle system which i tweaked to simulate a snow storm, but because it is maybe a bit performance expensive, i want rhe users to be able to enable or disable it as they need)

I'm not sure how to do that, because i don't know how to switch between the two states, and worst of all..., whatever i'm running the game and try to click the toggle...the toggle remains always as active in the screen (i got it to successfully disable the gameobject i mentioned...but, it remains as activated in the screen, and i can't click to enable the gameobject again...because the gameobject can't be reenabled)

What i want to do would be...

Dense Snow Storm: (Here would be the toggle, activated by default, and when clicked, set the gameobject to false and...possibly change the visual text from 'Enabled' to 'Disabled' on screen?)

I hope i explained my situation clearly, but only to be sure...

alt text

Thanks in advance!

question about toggles.jpg (41.6 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

2 Replies

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

Answer by Jamora · Jun 15, 2013 at 06:56 PM

I believe this snippet would work, though I haven't tested it. GO is the gameobject you want to set active/disabled by the toggle and toggleBool is a boolean class variable.

         if(toggleBool)
             toggleBool = GUI.Toggle (new Rect (25, 25, 100, 30), toggleBool, "Active");
         else
             toggleBool = GUI.Toggle (new Rect (25, 25, 100, 30), toggleBool, "Disabled");
         
         if(GUI.changed)
             GO.SetActive(toggleBool);
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
avatar image
0

Answer by Graham-Dunnett · Jun 15, 2013 at 08:21 PM

The following code will allow you to choose one of red, green, or blue. The selected value will be returned in the variable colGridInt as a value between 0 and 2.

 //js
 var colGridInt : int = 0;
 var colStrings : String[] = ["red", "green", "blue"];
           
 function OnGUI() {
     GUILayout.BeginVertical("Box");
     colGridInt = GUILayout.SelectionGrid (colGridInt, colStrings, 1, "toggle");
     
     if (GUILayout.Button("Start")){
         Debug.Log(colStrings[colGridInt]);
     }
     GUILayout.EndVertical();
 }
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

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

16 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

Related Questions

Help With Disabling/Enabling single GameObject 1 Answer

Why is a parent object accessed through the transform? 2 Answers

enable and disable boxcollider (whats wrong with my script?) 2 Answers

error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers

GameObject as a toggle button to play character Animation 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