Get rub value while touch a texture

Hi everyone.
Lately I am working on a little game. There is a GUITexture in the scene and when the user touch on the texture,I want to get access to its RGB value by touched position(maybe by coordinates… I guess). Is there anyone who might have any idea how to work on this, please help me out from this…thanks in advance.

You could try using Texture2D.ReadPixels to get your current screen pixel data

I’m not sure if the example code includes UI element’s or just 3D scene. If it’s just the 3D scene, then you’ll probably have to calculate the UV coordinate for your texture yourself. You know the GUITexture’s and position on screen so it should be pretty straightforward aswell.

Alternatively you could ditch the legacy GUI and use real 3D objects instead (like a simple quad plane). Then you could use regular raycasting, get UV coordinate from RaycastHit object and read the plane’s texture directly.

EDIT: You can read texture2D using this function: Unity - Scripting API: Texture2D.GetPixelBilinear

1 Like