Search Unity

Question Assess and change light explorer properties in script

Discussion in 'Scripting' started by lmz12321, Feb 25, 2024.

  1. lmz12321

    lmz12321

    Joined:
    Feb 20, 2024
    Posts:
    1
    Hello, I hope to read and change the properties of each light in Window > Rendering > Light Explorer > Lights from scripts. Is there a way to do this?

    I am a beginer to unity, so please forgive me if this is a naive question.

    Thanks!

    light explorer.png
     
  2. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    Yes. Get all the lights in your scene and modify them as you wish:


    Code (CSharp):
    1. // Get all the lights in the Scene
    2. var allLights = FindObjectsOfType<Light>();
    3.      
    4. // Cycle through all lights
    5. foreach (var light in allLights)
    6. {
    7.     // Set color to a yellowish one (red=1, green=1, blue=0.88, alpha (transparency)=1)
    8.     light.color = new Color(1f, 1f, 0.88f, 1f);
    9.  
    10.     // Dim light by 30%
    11.     light.intensity *= 0.7;
    12. }