Is their a way to get a texture and have it so that if a player paints one of the pixels with the right color, he gets 5 points. For example I have a 2d pixel apple. The player has to try and redraw the apple as best as he could. If he uses red and paints the apple correctly, he gets those 5 points. Is it possible for something like this and if so, what are some of the steps to create this?
private Color chosenColor;
private int _points;
private Color AppleColor { get { return Color.red; } }
private void CheckColor() {
if(chosenColor == AppleColor) {
_points += 5;
}
}
Something like that?
An approach that i think might work is that when the painting is done, you’d compare pixel by pixel (or maybe a 4x4 group of pixels that have their color averaged) of the original(source) and the new painting(target). You may want to give tolerances as getting the EXACT color value will be next to impossible (1 / 2^24 ?). If you exclude the alpha channel and just work with RGB, you get a Vector3. So this tolerance can be the ‘max distance’ from source to target. and possibly have tiers of tolerances that correspond to points awarded.
demo code:
Texture2D source;
Texture2D target;
float maxTolerance = 1.0f / 16.0f;
void CheckTextures()
{
if(source == null || target == null)
{
Debug.Log("source or target texture not initialised");
return;
}
if(source.width != target.width || source.height != target.height)
{
Debug.Log("source and target textures are not the same width or height");
return;
}
for (int x = 0; x < source.width; x++)
{
for (int y = 0; y < source.height; y++)
{
Color sourceColor = source.GetPixel(x,y);
Color targetColor = target.GetPixel(x,y);
Vector3 sourcePos = new Vector3(sourceColor.r, sourceColor.g, sourceColor.b);
Vector3 targetPos = new Vector3(targetColor.r, targetColor.g, targetColor.b);
if (Vector3.Distance(sourcePos, targetPos) <= maxTolerance)
{
// Grant points
}
}
}
}