Mouse down on GUIButton

How do I make something happen when I click a GUIButon but not on mouse release.

If I use this code:

if ((GUI.Button(Rect(800,100,110,110),btnTexture)))

it reacts when I release it :(

OnMouseDown OnMouseUp

I think if you make it work on function OnMouseDown () it should work :)

So don't put it in your function Update or whatever, make a seperate function:

function OnMouseDown(){ dowhatyouwantittodo; }

If you need action while the mouse is down, you can use `GUI.RepeatButton(..)` for it. If you want just one onmousedown, you can either add some manual checks or use a RepeatButton with a flag for being held down. Keep in mind, you should not be processing more than the bare minimum of code inside `OnGUI()` since this can get called several times per frame.

private var leftMouseClicked : boolean = false;

function OnGUI() {

	//used for on mousedown hack

	ix = Input.mousePosition.x; 

	iy = Input.mousePosition.y; 

	var transMouse = GUI.matrix.inverse.MultiplyPoint3x4(Vector3(ix, Screen.height - iy, 1));

	var closeButRect=Rect ((Screen.width/2) + 135,Screen.height - 470,14,14);
	GUI.Button(closeButRect,"", "closeBtn");
	if (leftMouseClicked){


			//mouse down on but - do something



//hack to get close buttons to respond on mouse down

function Update(){