• 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 this Toggle Texture thing.

i have this Texture in my Scene which 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 this 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 this 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, which 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

proper inventory system issue.. 1 Answer

how to change a gui button texture 1 Answer

inventory system - change GUI.DrawTexture texture 3 Answers

How to script GUI Texture Window to see it in Script (Object's component) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges