Particularly, how do you implement Color.GetBrightness (?)
public static bool isDark(Texture2D tex,float threshold=0.1f)
{
float sum = 0 ;
for (int x = 0; x < tex.width; x++)
{
for (int y = 0; y < tex.height; y++)
{
sum += GetBrightness(tex.GetPixel(x, y));
}
}
sum /= (int)(tex.width*tex.height);
if (sum < threshold) return false;
return true;
}
static float GetBrightness(Color color)
{
return (color.r + color.b + color.g) / 3f;
}