Reading Time: 4 minutes
In today’s tutorial, I’m going to show you how to add lighting in Unity version 2021 and above. The process has changed with this version. Building on previous tutorials, such as “Adding 2D Surface or Ground Limits in Unity,”
First, we need to install the Universal Render Pipeline plugin, which handles lighting and other features in Unity.
To do this, go to Window > Package Manager.
Once opened, switch to the Unity Registry to view the installable packages.
Now search for Universal RP and install it.
Once installed, close the window and create a folder called “RENDER” inside the project’s Assets.
Open the folder and right-click inside it, then select Rendering > URP Asset (with 2D Renderer).
Two files will be created, select the first one named New Universal Render Pipeline Asset.
Now, go to Edit > Project Settings.
Go to the Graphics tab.
Drag and drop the created render (New Universal Render Pipeline Asset) into Scriptable Render Pipeline.
Now, close the window and the settings will be applied.
In the next step, we need to convert the textures with the render to create the lighting.
To do this, open Window > Rendering > Render Pipeline Converter.
With the Convert Built-in to 2D (URP) tab selected, check the Material and Material Reference Upgrade option, and click Initialize Converters.
Once the scanning is done, click on Convert Assets.
Finally, close the window to save the configuration.
Now, to apply the lighting, create a new element in Hierarchy by right-clicking and selecting Light &php
Copy code
Now, to apply the lighting, create a new element in Hierarchy by right-clicking and selecting Light > Global Light 2D.
This element will control the lighting for all the objects in the scene.
By adjusting the intensity, you can increase or decrease the lighting in the scene. Lowering the intensity will make the scene darker.
Next, we need to create a light source to illuminate the scene. Create a new element in Hierarchy by right-clicking and selecting Light > Spot Light 2D.
By adjusting the intensity, you can control the brightness of the light source.
If you want to assign light directly to a character, create the light source within the character. Right-click on the character in Hierarchy and choose Light > Spot Light 2D.
Adjust the intensity to control the brightness of the light source by clicking on Intensity.
If you want an element to be unaffected by the light, you need to change its Material to Sprite Unlit Default.