- Home /
How can I match the position of my mouse cursor to the position of my texture?
Please, could you help me with the transform of coordinates?
I'm trying to make an indicator which changes its filling if I'm over it with my mouse cursor contiously. I've achieved to variate the level of filling when I pass my mouse cursor over it, but I've realised that the "y" coordinates of my mouse cursor don't match to the "y" coordinates of my texture. The fact is that When I pass my mouse cursor over my texture, my texture "fills" always with an offset which I can't determine. It's like if the cooordinates when Unity draws my texture were other different than the coordinates of my mouse: So, if I want to detect some differentiate zones of my texture I wil never success because the "y" coordinates of my texture and my mouse position are different.
My code:
var term_empty:Texture2D;
var term_filled:Texture2D;
private var b:float;
private var a:float;
private var ori_x :float;
private var ori_y:float;
private var dest_y:float;
private var offset_ini_y:float; //this the frame of the mobile content which moves when I pass the mouse cursor
private var offset_level_y:float;
ori_x=Screen.width / 5;
ori_y=Screen.height / 7;
dest_y=Screen.height*6/7;
offset_ini_y=20;
var screenPos : Vector2 = Event.current.mousePosition;
GUI.BeginGroup (Rect (ori_x,ori_y,160,620));
GUI.DrawTexture (Rect (0,0,160,620), term_empty,ScaleMode.ScaleToFit, true, 0);
b=ori_y+offset_ini_y;
a=ori_y+620-offset_ini_y;
if (GU.x >= 0 && GU.x<=160 && GU.y >=b && GU.y<a)
{
GUI.DrawTexture (Rect (0,0,160,620), term_filled,ScaleMode.ScaleToFit, true, 0);
GUI.BeginGroup (Rect (0,0,160,620-Input.mousePosition.y));
GUI.DrawTexture (Rect (0,0,160,620), term_empty,ScaleMode.ScaleToFit, true, 0);
}
// End both Groups
GUI.EndGroup ();
GUI.EndGroup ();
Debug.Log("Screen: " + screenPos + " GUI: " + GU);
How could I match them?.
Thanks in advance.
P.S.:I have no problem with my "x" coordinates.