- Home /
How do I make individual pixels of my objects sprite change color/disappear?
In my current unity project I want to make it so that I can make certain pixels of my objects sprite disappear or change color under certain conditions (such as the gameobject colliding with fire turning a random pixel black). I have no idea how to do this though and I couldn't find anything online that helped so I decided to create my own question. How do I do this or achieve a similar effect?
Answer by Catlard · Apr 28, 2020 at 02:57 AM
Hi! Three ways I can think of:
1) Use texture2d.getpixels/setpixels/apply, and change the actual image. Maybe not good for performance.
2) Place "pixels", i.e. squares of black color, individual sprites, right in front of your sprite. one layer higher. Round the positions of the pixels to a grid, and they'll always stay in "front" of a real pixel. This will take some fine tuning to make it look exactly right, though.
3) My preferred way: make a bunch of "burn" masks that are for various sides of the sprite. Turn these on or off based on what part of the sprite is burned. Could also use alpha to make it look gradually burned. avoids positioning problems as long as you keep the same image size from the original sprite.
Your answer
Follow this Question
Related Questions
How do I fill a Texture2D with pixels and display a sprite with that texture using script? 1 Answer
Slicing sliced sprite via script 0 Answers
Instantiate a gameObject with a dynamically generated sprite? 0 Answers
How to programmatically change image properties? 1 Answer
Can't create a 2D sprite with Sprite.Create when creating texture in code 1 Answer