x


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);

    }

}
}
more ▼

asked Feb 24 '12 at 10:11 PM

marchoward12 gravatar image

marchoward12
1 1 2 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Feb 25 '12 at 03:06 AM

Kleptomaniac gravatar image

Kleptomaniac
2.5k 6 12 21

(comments are locked)
10|3000 characters needed characters left

You should call Input.GetKeyDown in update and use it to set a boolean. Then in onGUI check for hud and this new boolean

more ▼

answered Feb 24 '12 at 11:11 PM

Blazor Ramone gravatar image

Blazor Ramone
134 1 2 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x55

asked: Feb 24 '12 at 10:11 PM

Seen: 606 times

Last Updated: Feb 25 '12 at 03:06 AM