4.6 - How do I change the value of a slider (Javascript)?

I have a bunch of sliders that I need to reset to zero. Ideally I would store them in an array, access the array members and set their value to 0. I’ve seen a few C# examples but nothing in Javascript.

I’m confused between the Slider game object and its Slider component and can’t access the value member of my sliders. This does not work:

private var allSliders : GameObject[];
        
function Start () 
{
    allSliders  = GameObject.FindGameObjectsWithTag("Slider");
    var thisSlider = allSliders[0].GetComponent("UnityEngine.UI.Slider");
    thisSlider.value = 0;
}

allSliders should refer to a all my gameObject sliders and thisSlider refer to their Slider component. But I get the ‘value’ is not a member of ‘UnityEngine.GameObject’ message. Can anyone set me straight on how to access a UI game object’s variable in Javascript?

to get component via name you use:
// import at the top of the script
import UnityEngine.UI;

// Access slider using
var thisSlider = allSliders[0].GetComponent("Slider");

If you want to get a component via type then you should use:

var thisSlider = allSliders[0].GetComponent(UnityEngine.UI.Slider);

So since you are trying to use second method so you need to remove the double quotes.

Here is the complete code solution, Javascript. Enjoy.
Be VERY careful with the syntax, its exxtremely case sensitive.

import UnityEngine.UI;
var mySlider: UnityEngine.UI.Slider;

function Start () {
     // substitute 'sliderName' with the literal name 
     // of your slider as it appears in the hierarchy:
     mySlider = GameObject.Find("sliderName").GetComponent(UnityEngine.UI.Slider);
}

function Update () {
     mySlider.value = n; 
     //insert desired variable here in place of 'n'
     // slider will automagically adjust to display new value
}