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 UnrealIzzy · Sep 06, 2012 at 08:36 PM · notepad

How Do I Show and Hide GUI?

Hi guys. I am making an In-Game-Notepad so the player can write down notes, and I am trying to make it so that the "Player" can press "`n`" on his/her keyboard and either `Show` or Hide the Notepad.

this is the script I have so far...

 var notePadText : String="NotePad...";
 
 function OnGUI () {
 
         notePadText = GUI.TextArea (Rect (5, 5, 200, 300), notePadText, 200);
 }

ok so now I wan't to make it so the player presses a button (on there keyboard) and the notepad shows and hides but I cannot figure out how I can achieve that.

Thank you in advance! -Izzy

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
6
Best Answer

Answer by Piflik · Sep 06, 2012 at 08:55 PM

Wrap your complete GUI code in an if statement, where you check if a boolean variable is true and then use the key to toggle it.

 var GUIEnabled : boolean = false;
 var notePadText : String="NotePad...";

 function Update () {
     if(Input.GetButtonUp("n")) {
         GUIEnabled = !GUIEnabled;
     }
 }

 function OnGUI () {
     if(GUIEnabled) {
         notePadText = GUI.TextArea (Rect (5, 5, 200, 300), notePadText, 200);
     }
 }
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 UnrealIzzy · Sep 06, 2012 at 09:08 PM 0
Share

Thank you! It works like a charm :D

I have made the script match my game and added in... Screen.lockCursor = false;

so that the players mouse show so he can select the notepad and when he hides the notepad... Screen.lockCursor = true;

$$anonymous$$eep up the great work!

avatar image Frsotbyte549 · Oct 05, 2014 at 08:04 PM 0
Share

HAHA im so stupid, it was so obvious. thank you piflik. although it was a bit off of what i was doing, i had to tweek it a little but you pointed out the obvious lol, thank you so much.

avatar image
0

Answer by z25assassins · Apr 02, 2017 at 10:09 AM

try this video https://www.youtube.com/watch?v=q2HZNZvFFoo&t=3s

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

11 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

Related Questions

How to hide/show GUI Buttons through another GUI Button? 2 Answers

Hide / Disable GUI.Textfield in scene 2 Answers

Creating a Notepad 1 Answer

MonoDevelop defaulted, Unity opens scripts in Notepad? 1 Answer

In Game Notepad 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