Find pixel colour under cursor position

Is there a way to find the colour located directly under the mouse cursor in Unity Free? I know I could find it easily enough if I just had a render texture and did some math, but render textures are a Pro only feature.

Well there are ways you can get the pixel information for a texture, but its gets a little tricky to do it in 3D. The right way I guess would be to raycast from the mouse position “forward” to whatever is being “aimed” at with the mouse, then it gets tricky. You would have to determine where on the surface of that texture that the collision happened, switch from world coordinates to the corresponding location on the surface of the texture, then call a GetPixel(x, y) at that location on the texture.

If it was just a 2D game, perhaps one with a quad in front of a camera, or a rendertexture drawn on screen - maybe you could just use getpixels much easier and find it.

So yeah look into GetPixel / GetPixels / GetPixels32 and figure which might work for ya.

EDIT: oh and if you are using a 3D game trying to do this, maybe figure out an alternative instead of finding the color of a single pixel, and instead get the color of the material, or just some hidden scripted value on whatever gets hit. It would probably be saving you some overhead of doing all that calculating to find a pixel.

if you want the color of pixel from a texture on an object, you can getpixel after raycasting, using the raycastHit.texcoord

if you want the color of the pixel after all rendering is done (so takes into account lighting, etc) you can use ReadPixels to grab the whole screen, then GetPixel on that.

Yeah, I need it to work in 3D and I need the pixel colour specifically since it’s for a colour coordination bit.

This requires the use of render textures, which are not available in Unity Free.

You can do it without render textures. I’m not positive but I think readpixels (like hpjohn said) lets you grab pixels from screen, keep em in a texture2d, where you can do getpixels. Only downside there is lighting and stuff could effect the color of the pixel… (also like hpjohn said)