x


GUI click through?

Hi, in my game there is a panel in the corner that has buttons in it, but when I click the button it registers in the world, creating an object, can I stop this?

more ▼

asked May 04 '10 at 09:08 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

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

2 answers: sort voted first

You're gonna want to take a look at the HitTest method.

You use it like this:

// C#
GUILayer l = Camera.main.GetComponent(typeof(GUILayer)) as GUILayer;
GUIElement ele = l.HitTest(Input.mousePosition);
if(ele != null)
{
     // The mouse is over a GUI element here. 
}
else
{
     // The mouse isn't over any GUI element here.
}
more ▼

answered May 04 '10 at 09:51 AM

qJake gravatar image

qJake
11.6k 43 78 161

thanks bro! helped a lot.

May 04 '10 at 10:17 AM Jason Hamilton

That works for GUIText and GUITexture, but what about buttons and such created with UnityGUI?

May 06 '10 at 06:24 AM yoyo

It should work for any GUI element.

May 06 '10 at 08:11 PM qJake

It works with any GUIElement, but the new UnityGUI system doesn't use those, and doesn't even require a GUILayer to work. You call GUI.Button every frame to create a button, for example.

May 07 '10 at 04:31 PM Pekuja

Any update on this in the last 10 months?

Feb 25 '11 at 07:32 PM Shadyfella13
(comments are locked)
10|3000 characters needed characters left

i made it through GUIUtility.hotControl

more ▼

answered Jun 03 '12 at 10:23 AM

FadeToBlack gravatar image

FadeToBlack
50 3

Thanks for the suggestion, you made my day!

Dec 19 '12 at 06:27 PM Kehos
(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:

x5076
x3682
x786

asked: May 04 '10 at 09:08 AM

Seen: 4919 times

Last Updated: Dec 19 '12 at 06:27 PM