So I've kind of got it to work using this:
using UnityEngine;
[RequireComponent
(typeof(UISlider
))] public class LevelPercentage : MonoBehaviour
{
UISlider mSlider;
UILabel mLabel;
void Awake ()
{
mSlider = GetComponent<UISlider>();
mSlider.eventReceiver = gameObject;
mLabel = GetComponent<UILabel>();
}
void OnSliderChange (float val)
{
mLabel.text = val.ToString ();
}
}
However, I don't know how to get it to point to the existing UISlider on my Progress Widget. As it is not, when attached to the UILabel it creates the UISlider because I have it set to require component. However, I want to ditch the require component and set it to point towards the existing UISlider. I have tried this:
using UnityEngine;
public class LevelPercentage : MonoBehaviour
{
[SerializeField] UISlider mSlider = null;
UILabel mLabel;
void Awake ()
{
mSlider = GetComponent<UISlider>();
mSlider.eventReceiver = gameObject;
mLabel = GetComponent<UILabel>();
}
void OnSliderChange (float val)
{
mLabel.text = val.ToString ();
}
}
I thought this would point towards the OnSlider FunctionName in the UISlider but it isn't. I am sure there is something simple I am missing here but I just can't see it. Any help?