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 Simon V · May 28, 2011 at 05:53 PM · gui

Issue with displaying GUI elements

Hello,

I'm currently writing a script for my GUI. They all react to keyboard input. Some parts, which should show up immediately, are only displayed after pressing the button, even though my code should work.

 public bool GUI_CrosshairsActive = true;
 
 void OnGUI ()
 {
     if (GUI_CrosshairsActive)
     GUI.DrawTexture(CrosshairsSize,Crosshairs);
 }
 
 private void CheckKeyboardInput()
 {        
     if (Input.GetKeyDown(KeyCode.N))
     {
         if (GUI_Crosshairsactive)
         {
             GUI_Crosshairsactive = false;
         }
         else
         {
             GUI_Crosshairsactive = true;
         }
     }
 }
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
2
Best Answer

Answer by Wolfram · May 28, 2011 at 06:42 PM

Make sure the value for GUI_CrosshairsActive in the Inspector is also "true". In case you added the initialization to "true" later in your script, the previous default value "false" will have been stored with the object, and the Inspector does not update on itself, even if you change the script afterwards.

If that is not the solution, we would need more information. Especially, who and when is CheckKeyboardInput() being called?

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 Simon V · May 28, 2011 at 06:49 PM 0
Share

Well, when declaring, I give it the 'true' value. But in the inspector it isn't checked. Check$$anonymous$$eyboardInput() is called in Update(). I have however found out that when I check if GUI_ChrosshairActive is not true, it works...

avatar image Wolfram · May 28, 2011 at 06:52 PM 1
Share

So the solution is simple: set the checkmark in the inspector, or delete the script from the object and re-attach it.

avatar image Simon V · May 28, 2011 at 06:56 PM 0
Share

Ok, thanks! ^^

avatar image
1

Answer by aldonaletto · May 28, 2011 at 06:45 PM

I'm not sure, but I think the problem is the public declaration of GUI_Crosshairsactive - it should be private instead. When you modify a public variable in the Inspector, the variable keeps the new value and completely ignores the initialisation value set in your script. So, if you have ever altered any instance of this variable in the Inspector, it will plague you for the rest of your lives (its and yours). Change it to private and try again.

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 Simon V · May 28, 2011 at 06:50 PM 0
Share

That could indeed be the problem.. However, I believe I hadn't done that when I first ran the script. And it wasn't working then either.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Issue with GUI.TextArea keyboard on iPhone 0 Answers

Bind Controller GUI to Input 0 Answers

BCE0004: Ambiguous reference 'Label' 1 Answer

Trigger an event from editor script? 0 Answers

How can I create complex tooltips 2 Answers


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