Can anyone help me with getting the texture coordinates when clicking a GUITexture ?
if tried the following raycast method with no succes on a GUITexture
void OnMouseUp()
{
// Only when interactive is enabled
if (!interactive)
return;
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
int x = /*width -*/ (int)(hit.textureCoord.x * width);
int y = height - (int)(hit.textureCoord.y * height);
}
}
I'm currently working on in-game browser rendered on a GUITexture. I got some working (See github repo) but I need some mouse support!
Typically this isn't used with GUITextures, but with 3d models. GUITextures aren't in the scene but rather, they float above it facing the camera. So I don't know of a good way to size a mesh collider for it properly without getting into some serious math.
Happily there is an easier way. Since a GUITexture is rectangular, all you need to know are the on-screen dimensions. Then you can compute what part of the image the mouse is over. Call GetScreenRect to get the screen rectangle of the GUITexture. Use it to convert the mouse's screen coordinates into the texture coordinates.