Question by 
               whatisitstudios_unity · Nov 21, 2020 at 03:41 PM · 
                lightflashlightdecrease  
              
 
              Decreasing Light Source
I am making a game where you have a flashlight, and the light slowly gets darker and darker until you can't see anything and the light has to charge up. I made some code and I tried it. But it doesn't work the way I want it to. I want it to change by a little bit every 0.25 seconds, but this changes WAY to fast. Could someone tell me what's wrong with my code?
 using System.Collections;
 
 using System.Collections.Generic;
 
 using UnityEngine;
 
 
 
 public class FlashlightBattery : MonoBehaviour
 
 {
 
 public Light light;
 
 
 
 public float maxLight;
 
 private float currentLight;
 
 
 
 void Start()
 
 {
 
 currentLight = maxLight;
 
 }
 
 
 
 void Update()
 
 {
 
 StartCoroutine(Light());
 
 }
 
 
 
 IEnumerator Light()
 
 {
 
 if(currentLight != 0)
 
 {
 
 for(int i = 50; i != 0; i--)
 
 yield return new WaitForSeconds(0.25);
 
 currentLight = currentLight - 0.01f;
 
 light.intensity = currentLight;
 
 }
 
 else
 
 {
 
 Debug.Log("No Light");
 
 }
 
 }
 
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
How can I make light edges more soft? 0 Answers
I don't know why my spotlight flashlight is going so crazy. Help? 1 Answer
Can't add game object to script 1 Answer
Fade Light in OnTriggerEnter and Fade Light out OnTriggerExit 2 Answers
Do constantly moving point lights cause optimization issues? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                