Search Unity

Question Only enable Lights for specific cameras

Discussion in 'Scripting' started by getmyisland_dev, Apr 9, 2021.

  1. getmyisland_dev

    getmyisland_dev

    Joined:
    Dec 22, 2020
    Posts:
    100
    Hello everyone,

    I have a lighting problem with my scene.

    I want to only enable a Light when I watch trough a specific camera.

    Means I switch to a camera and then the light activates trough a script, then I switch to another camera and another light activates and the light before goes off.

    I don't know how to start coding this, maybe one of you can help me.

    Just tell me if you need more information.

    Thanks in advance,
    Max
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I would have a script with references to all the lights, then whenever a camera change occurs you call some function on that script where you pass in an identifier for the camera. Could just be an int for the camera number, doesn't matter what kind of identifier you prefer. Then shut all lights off, then run through a switch statement which activates the correct light for that camera identifier.

    There's more ways to handle it though. For example, you could have the light actually a child of the camera GameObject. When you enable/disable the cameras you just turn on/off the entire camera GameObject. That way you don't need to script the lights at all, they turn on/off with the parent object, which again is the camera.
     
    getmyisland_dev likes this.