I want to change 2D Light properties through codes

Hi everyone!
So here I have a very frustrating problem with 2D lighting. It’s an Experimental feature in Unity 2019 and as you may know in the inspector window it’s being shown as a script not a built-in feature.
So, in 3D Lighting, you can simply make a Light reference in your code and then access to any properties of your lighting through that reference. But in 2D lighting I just can’t do that. I can’t make a reference in my code to change the properties of a, say, 2D Point Light.
I’m a beginner. If anyone can help me with this, please go ahead and give me your advice.

You should be able to do that.

Here’s a simple test case:

using UnityEngine;
using UnityEngine.Rendering.Universal;

public class TestLight : MonoBehaviour
{
    public Light2D light;

    void Update()
    {
        light.intensity = Mathf.PingPong(Time.time, 1f);
    }
}

edit: UnityEngine.Experimental.Rendering.Universal (old Unity versions) has become UnityEngine.Rendering.Universal instead (modern Unity versions). I updated the code sample above.

2 Likes

Thank you SO MUCH Lo-renzo.
I didn’t know I should add “using UnityEngine.Experimental.Rendering.Universal” at the beginning.

It is now UnityEngine.Rendering.Universal … Experimental has been removed

You are a saint for providing this update.

1 Like

I had the same issue myself lmao!

OK I updated my old answer so there’s no confusion any more :stuck_out_tongue: