How can I let mouse activity pass through my GUI?

I am using GUI elements as healthbars for my game, so there is a floating GUI Box with some other elements over certain objects in the scene. Everything is working great, except for one small problem that annoys me.

I have a MouseOver highlight script for the objects that are tagged, and when the mouse goes over the GUI boxes, the highlight script shuts off. So as you scroll across the object, it highlights, until you pass over the GUI, then it de-highlights, then highlights again when the mouse leaves the box.
I presume this is because even though these elements that I am using are non-clickable, the engine allows for the possibility that they might be clicked on.

Is there a way to turn off the interactiveness of certain GUI elements?

One approach might be to try using GUIStyle.Draw() to draw your GUI controls.

This allows you to determine the state (hover, active, on, focused) of your GUI controls manually.

You could make sure your GUI stays normal when your MouseOver script is active (or whenever a boolean is set by MouseOver).

I don't know if this will solve your problem, but it might be worth a try.

You could also try disabling the hover state of your GUI controls if you don't need hoverability.

You can do this by setting the background property of a GUIStyle's hover property to null (or by defining your own GUIStyle and/or GUISkin). The easiest way to do this is to use the inspector, but you can also do it with code:

public var myFunkyCustomSkin : GUISkin;

function OnGUI ()
{
    /* use my custom GUISkin */

    GUI.skin = myFunkyCustomSkin;

    /* get a GUIStyle named "myCustomStyle" from the gui skin */

    var someGuiStyle : GUIStyle = GUI.skin.GetStyle("myCustomStyle");

    /* remove the hover state */

    someGuiStyle.hover.background = null;
}

Again, I don't know if any of this will help with your specific problem....


One last idea might be to use the Event.Use() method. You can call this method on a mouse event, for example, to tell the GUI that you've already used the event and that it doesn't have to be processed further.

So… You might be able to have your MouseOver script set a boolean when you want the hover state to be ignored. When that boolean is true, you could simply call Event.current.Use() to skip processing it further. I have NO idea if that will work either!

Hope something in here helps... Good luck!