'Manipulating 2D Lighting with editor version 2021.2.19f1 with C#
I'm not sure what I am doing wrong, but I am currently having an issue manipulating the 2D lighting of objects. Everything looks normal in visual studio, no errors, but when I try to initialize the code in Unity, it errors out and says the object doesn't have Light on it. 2d lighting seems to be a script, instead of a different type of object like with 3d lighting, but I can't reference the script. It's very hard to find info on this because it seems like the URP gets updated very regularly, and nothing I've found explains what I need to do to manipulate the settings like intensity.
Does anyone have any advice for me?
Solution 1:[1]
First create a new 2D light by going to Light < 2D < Point Light 2D (You can use any Light).
Now you should have a 2D light in your scene. Next attach a script to the light for example LightManipulator.cs.
Inside of LightManipulator.cs you can now reference the 2D light by declaring it as a public variable.
public Light2D light;
You can now change various values of this light. For example setting the intensity to 0.5f.
light.intensity = 0.5f;
EDIT: You have to import this at the top using UnityEngine.Experimental.Rendering.Universal;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
