- Home /
Question by
grimreaperpt · Mar 15, 2014 at 06:35 PM ·
javascriptguisliderngui
NGUI - how do I put a value on a UISlider in Javascript?
I have a variable in javascript, let's say "health", that I would like to display it on a slider. How do I do that? I tried every way possible but it just doesn't work. Also, there's not any documentation available for javascript, I could only find for C# and I don't understand it.
I attached this script to my UI Root, but I'm getting error.
var sliderShowHealth : GameObject;
sliderShowHealth = GameObject.Find("healthBar");
function Update () {
sliderShowHealth.GetComponent(UISlider.Value) = //insert health variable here
}
Comment
Answer by gregroberts · Dec 23, 2014 at 01:06 AM
It took me like 4 hours of thrashing to figure this one out, so enjoy:
import UnityEngine.UI;
var sliderShowHealth: UnityEngine.UI.Slider;
function Start () {
sliderShowHealth = GameObject.Find("healthBar").GetComponent(UnityEngine.UI.Slider);
}
function Update () {
sliderShowHealth.value = //insert health variable here
}
OMG, that WORKS. You're welcome.