Question by
Rentrax · Aug 22, 2017 at 02:03 PM ·
c#scripting problemslider
Slider problem
Hi i created energy bar in my canvas. It is normal slider. I wrote a script in c# to control the slider value, but it still gives me an error. using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;
public class slider : MonoBehaviour {
public slider energy;
double Evalue = 0;
void Update () {
Evalue = energy.value;
}
}
How to make it start working. I cannot find a solution on internet.
Comment
Answer by UnityCoach · Aug 22, 2017 at 02:42 PM
You should use the Slider's onValueChanged event.
You can either add a listener to it from the inspector, or by code.
Note that your code, like using the event, will update a value with the slider value.
If you want to do the opposite, then you simply have to update the slider's value
property.