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 darkcookie · Apr 17, 2012 at 02:22 AM · guitoggle

why doesnt my script turn off on toggle?

I made a basic GUI that I want to turn on and off when I press the Key "E"....but the problem is that it doesn't toggle!!! I made a public Boolean called "MenuState" this defined the state if the GUI is on or off ...when I turn it on and off manually everything works but when I press the "E" key nothing happens....please some one help me ....tnx.

 using UnityEngine;
 using System.Collections;
 
 public class guiskin : MonoBehaviour
 {
     //variables start*********************************************************************
     public GUISkin thisOrangeGUISkin;
     public bool MenuState = false;
     private Rect rctWindow1;
     private Rect rctWindow2;
     private Rect rctWindow3;
     private Rect rctWindow4;
     private bool blnToggleState = false;
     private float fltSliderValue = 0.5f;
     private float fltScrollerValue = 0.5f;
 //    private Vector2 scrollPosition = Vector2.zero;
     //variables end***********************************************************************
 
 
     void update(){
         if(Input.GetKeyDown(KeyCode.E)){
             MenuState = true;
         }
         else{MenuState = false;}
         
     }
     
     
     void Awake()
     {
         rctWindow1 = new Rect(20, 20, 320, 400);
 }
     
     
 
         
     void OnGUI()
     {
         if(MenuState == true){
         GUI.skin = thisOrangeGUISkin;
                 rctWindow1 = GUI.Window(0, rctWindow1, DoMyWindow, "OPTIONS", GUI.skin.GetStyle("window"));
         }}
     
     
         
     
         
         void DoMyWindow(int windowID)
     {
         GUILayout.BeginVertical();
         GUILayout.Label("Im a Label");
         GUILayout.Space(8);
         GUILayout.Button("Im a Button");
         GUILayout.TextField("Im a textfield");
         GUILayout.TextArea("Im a textfield\nIm the second line\nIm the third line\nIm the fourth line");
         blnToggleState = GUILayout.Toggle(blnToggleState, "Im a Toggle button");
         GUILayout.EndVertical();
         GUILayout.BeginVertical();
         //Sliders
         GUILayout.BeginHorizontal();
         fltSliderValue = GUILayout.HorizontalSlider(fltSliderValue, 0.0f, 1.1f, GUILayout.Width(128));
         fltSliderValue = GUILayout.VerticalSlider(fltSliderValue, 0.0f, 1.1f, GUILayout.Height(50));
         GUILayout.EndHorizontal();
         //Scrollbars
         GUILayout.BeginHorizontal();
         fltScrollerValue = GUILayout.HorizontalScrollbar(fltScrollerValue, 0.1f, 0.0f, 1.1f, GUILayout.Width(128));
         fltScrollerValue = GUILayout.VerticalScrollbar(fltScrollerValue, 0.1f, 0.0f, 1.1f, GUILayout.Height(90));
         GUILayout.Box("Im\na\ntest\nBox");
         GUILayout.EndHorizontal();
         GUILayout.EndVertical();
         GUI.DragWindow();
     }
     
 }
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 aldonaletto · Apr 17, 2012 at 02:29 AM

You've written update, in lower case, but the correct name is Update. Furthermore, this code only sets MenuState to true during the frame where E is pressed. Toggle the variable this way:

    void Update(){
       if(Input.GetKeyDown(KeyCode.E)){
         MenuState = !MenuState; // toggle MenuState
       }
    }
Comment
Add comment · Show 1 · 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 darkcookie · Apr 17, 2012 at 02:31 AM 0
Share

thank you so much:)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Toggle GuiTexture 1 Answer

Can I have toggle buttons in a selection grid? 1 Answer

How does GUI.Toggle work? 2 Answers

Put toggle label on left side of button and hover 1 Answer

Is there a way of using just basic gui.Buttons as toggles? 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