- Home /
show gui label on key press
I have a gui label with an image that i want to display when a value is true and the key M has been pressed, but nothing is displaying with this code
var map : Texture2D;
function OnGUI () {
if (hud){
if(Input.GetKeyDown("m")){
GUI.Label (Rect (400, 40, map.width, map.height),map);
}
}
}
Answer by Kleptomaniac · Feb 25, 2012 at 03:06 AM
You don't appear to be defining 'hud' as a boolean? Is there a bit of the script missing because right now, 'hud' is never being defined and so can't be true, and therefore of course, it's not allowing you to bring up you're GUI label.
To define 'hud' try:
var hud : boolean = true;
Hope that helps, Klep
Answer by Blazor Ramone · Feb 24, 2012 at 11:11 PM
You should call Input.GetKeyDown in update and use it to set a boolean. Then in onGUI check for hud and this new boolean
Your answer
Follow this Question
Related Questions
What key was pressed? 4 Answers
Create GUIText by pressing key 1 Answer
Can't get simple script to work? 4 Answers
how can I destroying a spawn object ? 1 Answer
turning audio on and off 1 Answer