How to disable mouse input while over a gui?

Hi,

I’m new to Unity and I have a little situation here :smile:.
I can select an object by clicking on it. If I click somewhere else I deselect the object. (Classical rts style).
But if I try to click on a button while my object is selected it will deselect it…
So, how can I solve this problem? Is there a way to find out if the mouse is over a gui??

Thanks

++
Charlie

You must put some if statements in your functions. Actions must be made according to what you defined.

Unit selection and order giving are a little related (you give orders to selected units), but one must not prevent the other.

Basically, what I try to tell you is : think carefully about how you will code it, and there shouldn’t be any problems.

Thanks for your help !
I thought about what you said and change my design accordingly. It will be better this way.
However, I still have a little problem :
It works this way but I have to use GetMouseButtonUp in the Update function (which I don’t like very much).

private var m_ClickBtn : boolean = false;

function Update()
{
	if(!m_ClickBtn  Input.GetMouseButtonUp(0))
	{
		print("press mouse button down");
	}
}

function OnGUI()
{
	m_ClickBtn = false;
	
	if(GUI.Button(Rect(10, 10, icon.width, icon.height), icon))
	{
		m_ClickBtn = true;
		print("execute button");
	}
}

Is there another way so that I can use GetMouseButtonDown?

Thanks :slight_smile:

Use this : Unity - Scripting API: MonoBehaviour.OnMouseUp()