- Home /
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
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.
Awesome , thanks Jahroy
i added function Start to it.
Your answer
Follow this Question
Related Questions
GUI.toggle and GUI.horizontalSlider to GUItextures. 0 Answers
GUI texture touch input problem 1 Answer
GUI.DrawTexture on GUI.Button press 1 Answer
GUI_TEXTURE PROBLEM! 2 Answers
change the style of a gui by a key press 0 Answers