Select ui slider to change float value?
Hello i have a slider in my scene and i want it to change a float value from 1 to 3. But i dont know how to do this. If you can tell me how please do so, and use pictures! Thanks.
here is my code if needed:
 var Crosshair1 : GameObject;
 var Crosshair2 : GameObject;
 var Crosshair3 : GameObject;
 
 var SliderValue : float;
 
 function Update ()
 {
         //crosshairs
     if(SliderValue == 1)
     {
         Crosshair1.SetActive(true);
         Crosshair2.SetActive(false);
         Crosshair3.SetActive(false);
     }
     
     if(SliderValue == 2)
     {
         Crosshair1.SetActive(false);
         Crosshair2.SetActive(true);
         Crosshair3.SetActive(false);
     }
     
     if(SliderValue == 3)
     {
         Crosshair1.SetActive(false);
         Crosshair2.SetActive(true);
         Crosshair3.SetActive(false);
     }
 }
 
 //crosshairs
 function ChangeToCrosshair1 ()
 {
     SliderValue = 1;
 }
 
 function ChangeToCrosshair2 ()
 {
     SliderValue = 2;
 }
 
 function ChangeToCrosshair3 ()
 {
     SliderValue = 3;
 }
Answer by Xephex · Sep 03, 2015 at 02:39 AM
1: Go to GameObject > UI > Slider. 2: Set your upper and lower bounds as shown below. 
3: Then you can access the sliders current value in your script with something like this:
 var sliderObject : slider = GameObject.Find("name of your slider").GetComponent(Slider);
 SliderValue = sliderObject.value;
Now, your SliderValue variable should always be the same as the slider in the scene.
Possible helpful video: https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-slider
Your answer
 
 
             Follow this Question
Related Questions
Why Does Prefab Loose UI elements on Scene Change 0 Answers
"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar) 0 Answers
Mathf.Lerp with UI Slider to show reload time. 0 Answers
Make Multiple UI Sliders Function As One 1 Answer
UI Slider seting max value is delayed 0 Answers
