Hi, i am trying to get the number of red pixels within a map texture and then store the amount of them in a variable to use for other things, What would be the best way to do this in c#
thanks
Hi, i am trying to get the number of red pixels within a map texture and then store the amount of them in a variable to use for other things, What would be the best way to do this in c#
thanks
You can use Unity - Scripting API: Texture2D.GetPixels
And then check the value of each color. May be a little long though.
public Texture2D texture;
int GetRed()
{
int _result = 0;
Color[] _color = texture.GetPixels();
foreach(Color col in _color){
if(col == Color.red)_result++;
}
return _result;
}
This will return a value for any pixels fully red, you may want to makes it a little more flexible so that it includes color within a range of red like
if(col.r > 0.9 && col.g < 0.1 && col.b < 0.1)_result++;
this is regardless the alpha value.