- Home /
Changing light intensity with a slider
I'm using a gui slider to change the lights, but for some reason everything is just completely dark when I playtest it. It's written in C#.
Here's the code:
 using UnityEngine;
 using System.Collections;
 
 public class lights_intensity_slider : MonoBehaviour {
     
     public float intensity = 1f;
 
     public Rect SliderLocation;
 
     public Light[] lights;
     
     private float[] orglightsintensity = {0f,0f,0f,0f};
     
     void start() {
         
         for(int i=0;i<lights.Length;i++) {
             
             orglightsintensity[i]=lights[i].intensity;
         }
     }
     
     void Update() {
         
         for (int i=0; i < lights.Length; i++) {
             
             lights[i].intensity = orglightsintensity[i] * intensity;
         }
        
     }
 
     void OnGUI () {
 
         intensity = GUI.HorizontalSlider(SliderLocation, intensity, 0f, 2f);
        
     } 
 }
Answer by Eric5h5 · Oct 16, 2012 at 09:28 PM
Your "start" function will never execute, since there is no built-in function called that. You mean "Start".
Answer by pamz3d · Jul 27, 2016 at 07:11 PM
In the Lights segment you should assign size to 1. Then you will get Element 0 added to your Inspector. You should assign the light which you wanna test.
Can you please explain me how to us your script, cos i assigned your script to a Game Object. Only the slider moved, but nothing happened to the light which i assigned.
I have attached a reference pic of my workings. Hope someone will get something.

Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                