- Home /
How do I make my Sprite look Cracked
Hello,
I can't seem to find a soloution online, I expected to find a lot more people asking this question.
Basically, I want an object to show a crack overlay or something (I'm assuming using shaders) when it's health decreases. Kinda like Minecraft, when you start hitting a block.
The closest thing that I found was this shader
http://answers.unity3d.com/questions/204541/shaders-to-show-damage.html
but I think it's outdated, it has some errors.
Anyway, which direction should I be heading? right now I have it doing this
if (hitPoints <= 80) spriteRenderer.sprite = damagedSprite;
but that's just replacing the sprite.
Thanks a lot!!
make an animation. In animator, normalSprite -> animation -> brokenSprite
another way you could do it is to program a decal shader for sprites. You may of noticed the other Diffuse > Decal shaders unity has for regular 3d Objects. These shader will get a texture , and add another on top of it. which is similar what $$anonymous$$ecraft does(you'll notice in the texture packs of $$anonymous$$e craft the cracks and textures are stored separately).
I'm not a shader programmer myself, but the way I'd sort of do it , is draw one pixel from the first texture, then draw another on top of it from the second, the first texture being your sprite and the second being the progressive animated cracking sprite. you will need to animate in a script
another way might to be just to mix the color samples from the two textures (add, multiple, divide or subtract).
Anyway I'm not sure how the Sprite shaders work, I've only worked with a little 3D Diffuse type shaders.
Thank you for the replies! If I make an animation, does that mean I have to animate each type of block? There's 100's of different ones lol. Having it replace the sprite is also a problem as I'll have to make each block have a few phases. That's why I though it needs to be shaders. Unless I'm missing something? Fornoreason1000 I'm going to try what you said but I have no experience playing with shaders so may take a while to figure out lol.
Answer by Pflobus · Jan 14, 2015 at 04:25 AM
Yes. So, you could make an animation, and like a boolean (hit) that would be: hit = false, and when it's hit, it becomes hit = true, playing the animation, or you could replace the sprite.
Your answer
Follow this Question
Related Questions
2D Sprite Always Visible - Shader / Material not working (ZTest, ZWrite, Culling) 1 Answer
Render sprite only on top of a specific sorting layer 1 Answer
2D Sprite Highlight 0 Answers
Is it possible to have multiple stencil reference values in one shader? 0 Answers
Pixel snap for material made with Unlit Shader Graph? 1 Answer