- Home /
Question by
$$anonymous$$ · May 11, 2018 at 11:04 AM ·
spritescript.colorpixel
how can i change the color of a pixel in my sprite
I want to change some pixels by script
Comment
You'll need to convert the sprites texture into a color array, change the exact pixel in the array, and set the colors of the texture to the new array, then apply the changes.
Something like this... $$anonymous$$ay not be a copy & paste solution, but I hope you get the idea.
Colors[] pixels = mySprite.texture.GetPixels();
for (int x = 0; x < mySprite.texture.width)
{
for (int y = 0; y < mySprite.textute.height(
{
if (x == expectedXCoord && y == expectedYCoord)
{
pixels[x * y] = Color.black;
}
}
}
mySprite.texture.SetPixels(pixels);
mySprite.texture.Apply();
I'd recommend writing a custom shader that lets you control the color of certain pixels of a texture.