Slowly decrease the intensity of a light

Hi everyone,
I have got a problem with a script. I’m using js. In the scene I’ve got 5 windows. When I press “J” the window will move and the dore will be closed. The animation works fine. Now I’d like to see the intensity decrease when the animation start. This animation actually is 3 seconds long. It has to decrease from 1 to 0,8 in 3 seconds. Here is what I have. I wasn’t able to add a Time variable.

   private var volet1 : GameObject;
   volet1 = GameObject.Find("Volet1");

   private var Insidelight : GameObject;
   Insidelight = GameObject.Find("Insidelight");

    var intensityloss : float = 0.2;
 	
 	var Positionhaute : boolean = true;
     
    function Update () {
     
    if(Input.GetKeyUp(KeyCode.I) && Positionhaute)

    {
            volet1.animation.CrossFade("Volet1Close");
            Positionhaute = false;
          	Insidelight.light.intensity -= intensityloss * Time.deltaTime;;
    }

   else if(Input.GetKeyUp(KeyCode.I) && !Positionhaute)
    {
     	
            
       		volet1.animation.CrossFade("Volet1Open");
            Positionhaute = true;
     		Insidelight.light.intensity += intensityloss * Time.deltaTime;;
    }
     
     
   }

Tu connais le point de départ (1), le point d’arrivé (0,8) et la durée (3s)
Donc tu peux calculer la vitesse : v = ( 1 - 0.8 )/3
Comme il s’agit d’une vitesse en unit/frame il faut le convertir en unit/sec avec Time.deltaTime

donc tu créé une variable privé intensityLoss:float,
tu l’initialise dans function Start():

intensityLoss = ( intensityStart - intensityEnd ) / intensityTime;

et dans Update tu place cette commande:

Insidelight.light.intensity += intensityloss * Time.deltaTime;

et enfin tu vérifies que l’intensité ne descend pas en dessous de intensityEnd