Creating drop shadows for Sprites in Unity

July 27, 2019



Many Unity games use drop shadows for sprites to add shadows to 2D games. In this article, we will be creating a simple and cool looking shadow for a sprite.
The final shadow will look like:

Setting up the Project

To get started, I have created an empty Unity 2D project with the sprite imported.

Creating the Material for Shadow

To create a drop shadow, we need to create a new material by right-clicking the project view and clicking Create -> Material. This will create a new material in the project. Now we need to change the shader of the material to GUI/Text Shader.


We will be using this material for the shadow of a sprite.
Now change the Text Color of the material to something dark, as this will be our shadow color.

Creating the Shadow

Now we will be creating the drop shadow for a sprite.
Start by simply importing any sprite in the scene view. Now create a new script named DropShadow.cs and attach it to the sprite in the scene view. Now replace the script content with the following code.

Now select the sprite in the Project Hierarchy and update the values of Drop Shadow script in the inspector to the following values.
Set the Shadow Offset to (0.2, 0.2)
Drag and drop the material you created in the Shadow Material field.
Hit the Play button and check the drop shadow creating behind the sprite in the game view.

You Might Also Like

1 comments

  1. Nice and amazing post. This tutorial is very helpful and informative post. Thanks for sharing with us.

    ReplyDelete

Follow by Email