• 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
1
Question by .ashen_verdict. · Dec 17, 2011 at 11:30 PM · guitextureguitextureinventorytoggle

Toggle GUITexture V.2

Yo! Unity Answers, ( first time here) so i need help with t$$anonymous$$s Toggle Texture t$$anonymous$$ng.

i have t$$anonymous$$s Texture in my Scene w$$anonymous$$ch is the Inventory GuiTexture show in Picture1.

http://imageshack.us/photo/my-images/546/gui1.png/

i can toggle it on and off no problem, but the problem is whenever i start my game the Inventory GuiTexture is on ToggleOn mode.

what i need is that the Inventory GuiTexture is on ToggleOff Mode when i start my game, show in Picture2

http://imageshack.us/photo/my-images/842/gui2j.png/

here's the script of Inventory GuiTexture


function Update() {

  if (Input.GetKeyDown(KeyCode.F1)) {

     guiTexture.enabled = !guiTexture.enabled;

     }

}


--thanks to Kith for the script

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

Answer by jahroy · Dec 17, 2011 at 11:35 PM

Add t$$anonymous$$s to the Start function of your script:

guiTexture.enabled = false;

It will set the value of guiTexture.enabled to false when your script is enabled.

If you don't have a Start function, you can create one by adding t$$anonymous$$s to your script:

function Start ()
{
    guiTexture.enabled = false;
}

The code inside the Start function gets called one time when your script gets enabled.

 


 

FYI:

The code you already have executes every frame because it's in a function named Update. Every frame it checks whether or not the F1 key is pressed.

If F1 was pressed during the current frame, it executes the code in the if block, w$$anonymous$$ch toggles the value of the enabled property of the guiText attached to the GameObject with your script.

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 .ashen_verdict. · Dec 18, 2011 at 07:38 AM 0
Share

Awesome , thanks Jahroy

i added function Start to it.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

GUI.toggle and GUI.horizontalSlider to GUItextures. 0 Answers

inventory system - change GUI.DrawTexture texture 3 Answers

proper inventory system issue.. 1 Answer

how to change a gui button texture 1 Answer

How to script GUI Texture Window to see it in Script (Object's component) 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