how to control 2 lights with one button?

hello there,

my coding skills are not sufficient for this presumably easy task. i searched through the forums and couldnt find what i am looking for, so i need your help. here is the question.

i have 2 lights in the scene and a button to control them to make a very simple day/night cycle-loop. 1 directional light and a spot light. at the begining i need the directional light to be active(on) and the spot light to be inactive(off). and when i hit the button i need it to change it otherwise: turn directional light off and turn spot light on…

is there a way out there to do this? i really appreciate for the help…

This should do what you want:

var dirLight : GameObject;
var spotLight : GameObject;

function Start()
{
    dirLight.enabled = true;
    spotLight.enabled = false;
}

function Update()
{
    if(Input.GetKeyDown(KeyCode.L))
    {
        dirLight.enabled = !dirLight.enabled;
        spotLight.enabled = !spotLight.enabled;
    }
}

Is simple if/else events not working ? for example

  var light1 : GameObject;
    var light2 : GameObject;
    
    //if/else event 
    {
     light1.enabled = true;
     light2.enabled = false;
    }

var light1 : GameObject;
var light2 : GameObject;
function Update () {
if (Input.GetKeyDown(KeyCode.L))
{
light1.enabled = true;
}
else
{
light2.enabled = false;
}
}

i dont know what i am doing wrong but here you go… and another thing is light2 has to be off while light 1 is on at the begining of the gameplay

var light1 : GameObject;
var light2 : GameObject;
function Update () {
if (Input.GetKeyDown(KeyCode.L))
{
light1.enabled = true;
}
else
{
light2.enabled = false;
}
}

i did this and attached the lights but no luck. and one more thing: light1 has to be on and light2 has to be off at the begining of the game play…