Sprite Flash in Unity

Ilham Effendi
2 min readJul 22, 2019

--

Sprite Flashing in Burst Fighter (Small turrets are flashing when it gets hit)

Flashing effect is commonly used in Shoot ’Em Up and Beat ’Em Up games. It gives clue to players that those enemies or objects can be damaged and destroyed. I used this technique in the development of Burst Fighter. (The spaceships image below is from Burst Fighter)

Sprite Flashing

The implementation in Unity is actually quite simple. We just need to change the default sprite shader with our custom flash shader that we will be creating right now. I won’t explain the basic of shader programming. You can find it on the internet easily. I personally recommend reading this article by Alan Zucconi before diving into shader programming.

The shader will look like this:

Look closer to this line.

c.rgb = lerp(c.rgb, _FlashColor.rgb, _FlashAmount);

The idea is we want to lerp our existing sprite color to _FlashColor based on _FlashAmount. Now, create a new material with this shader and attach it to your sprite. Next step is creating a C# script to interact with _FlashAmount value.

It’s quite easy to manipulate shader’s variable in C#. You can use SetFloat() to change float value and SetColor() to change color value. That’s it! Now start play mode and press Space bar to flash the sprite.

You can download the Unity project here: Unity Sprite Flash

--

--