Can I control Lighting2D intensity with script? (Unity C#)

Viewed 400

people, I have little problem. I need to have access on 2D light intensity from script. I tried doing it with GetComponent<>, but it didn't work. Maybe, I did something wrong with GetComponent<>, because I'm starter. Screenshot of what I want to control

1 Answers

You can call for GetComponent<>() but you might be doing it wrong.

using UnityEngine;
using UnityEngine.Experimental.Rendering.Universal;

    public class ControllingIntensity : MonoBehaviour
    {
        public float intensity;

        void Start()
        {
            GetComponent<Light2D>().intensity = intensity;
        }
    }
Related