- Home /
getPixel co-ordinates not screen co-ordinates based on mouse position
Hi, im trying to get the x,y co-ordinates of a pixel to use in the GetPixel function. I have tried using a raycast to get the hit position based on Camera.main.WorldToScrenPoint however this gives a screen co-ordinate, not a pixel co-ordinate on the readable texture. So how do you do it, by that i mean get pixel co-ordinates off a specific texture in the scene when the mouse is over it.
Answer by aldonaletto · Oct 11, 2011 at 08:52 PM
You should use the Raycast, but from the RaycastHit structure returned, get textureCoord: it's the UV coordinates of the pixel hit. The docs give in the link above an example of how to set the pixel hit - it's probably easy to adapt to your case.
Answer by DaveA · Oct 11, 2011 at 08:51 PM
http://unity3d.com/support/documentation/ScriptReference/RaycastHit.html check out textureCoord
Your answer
Follow this Question
Related Questions
How to pixelate an image texture for faster pixel color recognition? 2 Answers
Translate a pixel using SetPixel on a Texture2D? 1 Answer
How can I check how many pixels on a texture are transparent without tanking performance? 4 Answers
How to find out which object is under a specific pixel 1 Answer