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 bruno martelli_legacy · Aug 29, 2010 at 01:31 PM · guitexturehidekeypressshow

Show & Hide GUItexture on keypress

  • I'd like to toggle a GUItexture to appear/disappear. this code (below) i saw elsewhere on the forum hides and shows a mesh, but not a GUItexture. any idea how to make the code hide a GUI textue. (Sorry im not a programmer.)

function Update() {

if (Input.GetKeyDown(KeyCode.Z)) { // show renderer.enabled = true; }

if (Input.GetKeyDown(KeyCode.X)) { // hide renderer.enabled = false; }

}

Comment
Add comment · Show 1
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 bruno martelli_legacy · Aug 29, 2010 at 02:02 PM 0
Share

this script is quite a sexy answer: http://www.unifycommunity.com/wiki/index.php?title=FadeIn

3 Replies

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

Answer by Ippokratis · Aug 29, 2010 at 02:58 PM

In the inspector create an empty gameobject. Name it GuiHere. Create a new js script called MyGui.js and paste the following code

function OnGUI  () {
GUI.Label (Rect (10, 10, 100, 20), "Hello World!");
}

Add MyGui.js to the GuiHere. Now create a new js script called Controller.js and paste the following code

var Guiscript : MyGui ;

function Update () {

if (Input.GetKeyDown ("space")){ if (Guiscript.enabled == true){ Guiscript.enabled = false; } else { Guiscript.enabled = true; } } }

Add the Controller.js to the Main camera. Add the GuiHere object in the slot of the Controller.js in the Main camera object.

Hit play. When you press the space bar, the gui appears. If you press it again, it disappears. By checking the drawcalls, you will see that it is completely disabled, not just not showing. For further reading, I would suggest http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html and http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.html

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 sooshicat · Sep 28, 2012 at 02:07 PM 0
Share

This works great, but how do you change it from the Hello World text to an actual texture?

avatar image sooshicat · Sep 28, 2012 at 02:17 PM 0
Share

and also when i click play the texture is already there..

avatar image rev3rse · Jan 20, 2014 at 07:55 PM 0
Share

A cleaner version:

 if (Input.Get$$anonymous$$eyDown ("space")){
        Guiscript.enabled = !Guiscript.enabled;
     }
avatar image
0

Answer by jtbentley · Aug 30, 2010 at 03:02 PM

gameObject.guiTexture.enabled = false;

That might be deprecated?

gameObject.guiTexture.active = false :)

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 Ippokratis · Feb 03, 2011 at 04:14 PM 0
Share

Thanks for bringing this to my attention. It might work both ways, haven't tested your suggestion though. The method you suggest should deactivate the gameObject (gameObjects are active/inactive) while the method I suggest deactivates the $$anonymous$$onoBehaviour (enabled/disabled). I think that since ot is here http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.html it is not depreciated. Anyway, I didn't knew the active / inactive variable until now, so thanks.

avatar image
0

Answer by M Poirot · Apr 30, 2011 at 07:55 PM

for GUI's id like to use

if (Input.GetKeyDown(KeyCode.Z)){ // show Gameobject.guiText.enabled = true; }

if (Input.GetKeyDown(KeyCode.X)) { // hide
gameobject.guiText.enabled = false; }

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

2 People are following this question.

avatar image avatar image

Related Questions

Show/hide GUI texture 2 Answers

on collision, show/hide other model scripting ? 1 Answer

Hide GUI Text when button is pressed 1 Answer

hide show canvas and ui elements at start 1 Answer

hide and show node for turret places 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