Input.mouse position on GUI Textures

I have 2 gui textures.

According to screen width and height i kept it in gui.

One for joystick and another for shooter.

Now touching on shooter joystick moves to that specific portion.

i used rect.Contains.

if (rect.Contains(Input.mousePosition)){
shootBool = true;
print("shooter gui Inside");
alert.text="shooter gui Inside";
}

Not working properly for me. Think space coordinates are different from gui coordinates. How can fix this problem.

I’m guessing you are using Input.mousePosition. This variable is in Screen coordinates. GUI lives in GUI coordinates. You can convert between the two by:

Pos.y = Screen.height - Pos.y;

But a better solution is to use GUI events. See Event.mousePosition.

Since it is GUI,like a GUITexture, You can attach a script to the GUITexture and call OnMouseDown, or OnMouseOver.

var hovertex : Texture2D;
var normaltex : Texture2D;

function OnMouseDown(){

print("Pressed");

}

function OnMouseOver(){

print("HOvering");

}