I've got this script that should be reading the color of a pixel on the screen but it never returns the right result. For example; it will return black even though there's a giant white object on screen. What am I doing wrong? Here's the code:
#pragma strict
var colorOfPixel1 : Color;
var tex2D : Texture2D;
function ReadScreen() {
tex2D = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
yield WaitForEndOfFrame();
tex2D.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
tex2D.Apply();
colorOfPixel1 = tex2D.GetPixel(0, 0);
}
function Start() {
}
function Update() {
ReadScreen();
}
↧