Home › Page › UghSlider


Inherits from UghControl

UghSlider is an UghControl that provides a track and thumb interface.  This is useful to represent a control that can be adjusted for a range of values.  Good examples include a control to adjust sound volume, or a timeline scrubber for a sound or animation.  The UghSlider represents the thumb object.  (Another UghSprite can be used to represent the track.)

To setup an UghSlider, you must specify an UghSpriteDefinition for the normal and pressed variables, and then define the range of track in the visualWidthUnits variable.  You can read the current value of the UghSlider with the Current attribute.  If you want to respond to changes in the slider, register for the OnChanged event.  This event will get fired every frame that the thumb changes position.

name type description
Current float The current value of the slider (as defined by the current thumb position and the limits variable.)
CurrentNormalized float The current position of the thumb along the slider, as a fractional value from 0 to 1.
limits Rangef The range of values allowed for the UghSlider (ie 0-100 for volume).
pressed UghSpriteDefinition The sprite visible when the thumb is being dragged.
visualWidthUnits float The width of the track, in Unity units.
name type description
OnChanged event An event fired whenever the position of the thumb has changed.


Using UghSlider in script

UghSlider inherits all of the same event functions as any UghControl:

public override IEnumerator OnUghInputDown();
public override void OnUghInputUp();
public override void OnUghInputUpAsButton();

These events fire under the same situations as an UghButton, and an UghSlider behaves much like an UghButton that can be dragged along a track.

There is also an event that gets fired off whenever an UghSlider’s value is changed. You can register for this event in order to respond to changing values.  Note that the event is fired every frame that the UghSlider has changed position.

public event Action OnChanged;