docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Slider

    A standard slider that can be moved between a minimum and maximum value.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    UIBehaviour
    Selectable
    Slider
    Implements
    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IDragHandler
    IInitializePotentialDragHandler
    IEventSystemHandler
    ICanvasElement
    Inherited Members
    Selectable.s_Selectables
    Selectable.s_SelectableCount
    Selectable.allSelectablesArray
    Selectable.allSelectableCount
    Selectable.AllSelectablesNoAlloc(Selectable[])
    Selectable.m_CurrentIndex
    Selectable.navigation
    Selectable.transition
    Selectable.colors
    Selectable.spriteState
    Selectable.animationTriggers
    Selectable.targetGraphic
    Selectable.interactable
    Selectable.image
    Selectable.animator
    Selectable.Awake()
    Selectable.OnCanvasGroupChanged()
    Selectable.IsInteractable()
    Selectable.OnTransformParentChanged()
    Selectable.Reset()
    Selectable.currentSelectionState
    Selectable.InstantClearState()
    Selectable.DoStateTransition(Selectable.SelectionState, bool)
    Selectable.FindSelectable(Vector3)
    Selectable.IsHighlighted()
    Selectable.IsPressed()
    Selectable.OnPointerUp(PointerEventData)
    Selectable.OnPointerEnter(PointerEventData)
    Selectable.OnPointerExit(PointerEventData)
    Selectable.OnSelect(BaseEventData)
    Selectable.OnDeselect(BaseEventData)
    Selectable.Select()
    UIBehaviour.Start()
    UIBehaviour.OnDestroy()
    UIBehaviour.IsActive()
    UIBehaviour.OnBeforeTransformParentChanged()
    UIBehaviour.OnCanvasHierarchyChanged()
    UIBehaviour.IsDestroyed()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.didStart
    MonoBehaviour.didAwake
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.GetComponentIndex()
    Component.CompareTag(string)
    Component.CompareTag(TagHandle)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.transformHandle
    Component.gameObject
    Component.tag
    Object.GetEntityId()
    Object.MemberwiseClone()
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.InstantiateAsync<T>(T, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate<T>(T, InstantiateParameters)
    Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectsByType(Type)
    Object.FindObjectsByType(Type, FindObjectsInactive)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectsByType<T>()
    Object.FindObjectsByType<T>(FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: UnityEngine.UI
    Assembly: UnityEngine.UI.dll
    Syntax
    [AddComponentMenu("UI (Canvas)/Slider", 34)]
    [ExecuteAlways]
    [RequireComponent(typeof(RectTransform))]
    public class Slider : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IDragHandler, IInitializePotentialDragHandler, IEventSystemHandler, ICanvasElement
    Remarks

    The slider component is a Selectable that controls a fill, a handle, or both. The fill, when used, spans from the minimum value to the current value while the handle, when used, follow the current value. The anchors of the fill and handle RectTransforms are driven by the Slider. The fill and handle can be direct children of the GameObject with the Slider, or intermediary RectTransforms can be placed in between for additional control. When a change to the slider value occurs, a callback is sent to any registered listeners of UI.Slider.onValueChanged.

    Constructors

    Slider()

    Protected default constructor. Use UnityEngine.GameObject.AddComponent<T>() to add a Slider to a GameObject.

    Declaration
    protected Slider()

    Fields

    m_Value

    Serialized backing field for value.

    Declaration
    [SerializeField]
    protected float m_Value
    Field Value
    Type Description
    float

    Properties

    direction

    The direction of the slider, from minimum to maximum value.

    Declaration
    public Slider.Direction direction { get; set; }
    Property Value
    Type Description
    Slider.Direction
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        public void Start()
        {
            //Changes the direction of the slider.
            if (mainSlider.direction == Slider.Direction.BottomToTop)
            {
                mainSlider.direction = Slider.Direction.TopToBottom;
            }
        }
    }

    fillRect

    Optional RectTransform to use as fill for the slider.

    Declaration
    public RectTransform fillRect { get; set; }
    Property Value
    Type Description
    RectTransform
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;  // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
        //Reference to new "RectTransform"(Child of FillArea).
        public RectTransform newFillRect;
    
        //Deactivates the old FillRect and assigns a new one.
        void Start()
        {
            mainSlider.fillRect.gameObject.SetActive(false);
            mainSlider.fillRect = newFillRect;
        }
    }

    handleRect

    Optional RectTransform to use as a handle for the slider.

    Declaration
    public RectTransform handleRect { get; set; }
    Property Value
    Type Description
    RectTransform
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
        //Reference to new "RectTransform" (Child of "Handle Slide Area").
        public RectTransform handleHighlighted;
    
        //Deactivates the old Handle, then assigns and enables the new one.
        void Start()
        {
            mainSlider.handleRect.gameObject.SetActive(false);
            mainSlider.handleRect = handleHighlighted;
            mainSlider.handleRect.gameObject.SetActive(true);
        }
    }

    maxValue

    The maximum allowed value of the slider.

    Declaration
    public float maxValue { get; set; }
    Property Value
    Type Description
    float
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        void Start()
        {
            // Changes the max value of the slider to 20;
            mainSlider.maxValue = 20;
        }
    }

    minValue

    The minimum allowed value of the slider.

    Declaration
    public float minValue { get; set; }
    Property Value
    Type Description
    float
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        void Start()
        {
            // Changes the minimum value of the slider to 10;
            mainSlider.minValue = 10;
        }
    }

    normalizedValue

    The current value of the slider normalized into a value between 0 and 1.

    Declaration
    public float normalizedValue { get; set; }
    Property Value
    Type Description
    float
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        //Set to invoke when "OnValueChanged" method is called.
        void CheckNormalisedValue()
        {
            //Displays the normalised value of the slider everytime the value changes.
            Debug.Log(mainSlider.normalizedValue);
        }
    }

    onValueChanged

    Callback executed when the value of the slider is changed.

    Declaration
    public Slider.SliderEvent onValueChanged { get; set; }
    Property Value
    Type Description
    Slider.SliderEvent
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        public void Start()
        {
            //Adds a listener to the main slider and invokes a method when the value changes.
            mainSlider.onValueChanged.AddListener(delegate {ValueChangeCheck(); });
        }
    
        // Invoked when the value of the slider changes.
        public void ValueChangeCheck()
        {
            Debug.Log(mainSlider.value);
        }
    }

    value

    The current value of the slider.

    Declaration
    public virtual float value { get; set; }
    Property Value
    Type Description
    float
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        //Invoked when a submit button is clicked.
        public void SubmitSliderSetting()
        {
            //Displays the value of the slider in the console.
            Debug.Log(mainSlider.value);
        }
    }

    wholeNumbers

    Should the value only be allowed to be whole numbers?

    Declaration
    public bool wholeNumbers { get; set; }
    Property Value
    Type Description
    bool
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        public void Start()
        {
            //sets the slider's value to accept whole numbers only.
            mainSlider.wholeNumbers = true;
        }
    }

    Methods

    FindSelectableOnDown()

    Find the selectable object below this one.

    Declaration
    public override Selectable FindSelectableOnDown()
    Returns
    Type Description
    Selectable

    The nearest Selectable below, or null.

    Overrides
    Selectable.FindSelectableOnDown()
    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class Example : MonoBehaviour
                            {
                                public Button startButton;
    
                                // Disables the selectable UI element directly below the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element below the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnDown();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    FindSelectableOnLeft()

    Find the selectable object to the left of this one.

    Declaration
    public override Selectable FindSelectableOnLeft()
    Returns
    Type Description
    Selectable

    The nearest Selectable to the left, or null.

    Overrides
    Selectable.FindSelectableOnLeft()
    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class ExampleClass : MonoBehaviour
                            {
                                public Button btnMain;
    
                                // Disables the selectable UI element directly to the left of the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element to the left the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnLeft();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    FindSelectableOnRight()

    Find the selectable object to the right of this one.

    Declaration
    public override Selectable FindSelectableOnRight()
    Returns
    Type Description
    Selectable

    The nearest Selectable to the right, or null.

    Overrides
    Selectable.FindSelectableOnRight()
    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class ExampleClass : MonoBehaviour
                            {
                                public Button btnMain;
    
                                // Disables the selectable UI element directly to the right the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element to the right the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnRight();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    FindSelectableOnUp()

    The Selectable object above current

    Declaration
    public override Selectable FindSelectableOnUp()
    Returns
    Type Description
    Selectable

    The nearest Selectable above, or null.

    Overrides
    Selectable.FindSelectableOnUp()
    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class ExampleClass : MonoBehaviour
                            {
                                public Button btnMain;
    
                                // Disables the selectable UI element directly above the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element above the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnUp();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    GraphicUpdateComplete()

    See ICanvasElement.GraphicUpdateComplete

    Declaration
    public virtual void GraphicUpdateComplete()

    LayoutComplete()

    See ICanvasElement.LayoutComplete

    Declaration
    public virtual void LayoutComplete()

    OnDidApplyAnimationProperties()

    Called when animation properties are applied. Updates the slider visual state.

    Declaration
    protected override void OnDidApplyAnimationProperties()
    Overrides
    Selectable.OnDidApplyAnimationProperties()

    OnDisable()

    Called when it becomes disabled. Unregisters from canvas rebuilding.

    Declaration
    protected override void OnDisable()
    Overrides
    Selectable.OnDisable()

    OnDrag(PointerEventData)

    Called while dragging the slider. Updates the value based on the drag position.

    Declaration
    public virtual void OnDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the drag.

    OnEnable()

    Called when it becomes enabled. Registers for canvas rebuilding and updates visuals.

    Declaration
    protected override void OnEnable()
    Overrides
    Selectable.OnEnable()

    OnInitializePotentialDrag(PointerEventData)

    Called when a potential drag is detected. Disables inertia for immediate response.

    Declaration
    public virtual void OnInitializePotentialDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data.

    OnMove(AxisEventData)

    Called when a move event occurs. Adjusts the value by one step in the specified direction.

    Declaration
    public override void OnMove(AxisEventData eventData)
    Parameters
    Type Name Description
    AxisEventData eventData

    The axis event data containing the move direction.

    Overrides
    Selectable.OnMove(AxisEventData)

    OnPointerDown(PointerEventData)

    Called when the pointer is pressed on the slider. Sets the value based on the press position.

    Declaration
    public override void OnPointerDown(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the press.

    Overrides
    Selectable.OnPointerDown(PointerEventData)

    OnRectTransformDimensionsChange()

    Called when the RectTransform dimensions change. Updates the slider visual state.

    Declaration
    protected override void OnRectTransformDimensionsChange()
    Overrides
    UIBehaviour.OnRectTransformDimensionsChange()

    OnValidate()

    Declaration
    protected override void OnValidate()
    Overrides
    Selectable.OnValidate()

    Rebuild(CanvasUpdate)

    Called by the canvas update system to rebuild the slider fill and handle visuals.

    Declaration
    public virtual void Rebuild(CanvasUpdate executing)
    Parameters
    Type Name Description
    CanvasUpdate executing

    The current canvas update stage.

    Set(float, bool)

    Set the value of the slider.

    Declaration
    protected virtual void Set(float input, bool sendCallback = true)
    Parameters
    Type Name Description
    float input

    The new value for the slider.

    bool sendCallback

    If the OnValueChanged callback should be invoked.

    Remarks

    Process the input to ensure the value is between min and max value. If the input is different set the value and send the callback is required.

    SetDirection(Direction, bool)

    Sets the direction of this slider, optionally changing the layout as well.

    Declaration
    public void SetDirection(Slider.Direction direction, bool includeRectLayouts)
    Parameters
    Type Name Description
    Slider.Direction direction

    The direction of the slider

    bool includeRectLayouts

    Should the layout be flipped together with the slider direction

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class Example : MonoBehaviour
    {
        public Slider mainSlider;
    
        public void Start()
        {
            mainSlider.SetDirection(Slider.Direction.LeftToRight, false);
        }
    }

    SetValueWithoutNotify(float)

    Set the value of the slider without invoking onValueChanged callback.

    Declaration
    public virtual void SetValueWithoutNotify(float input)
    Parameters
    Type Name Description
    float input

    The new value for the slider.

    Update()

    Update the rect based on the delayed update visuals. Got around issue of calling sendMessage from onValidate.

    Declaration
    protected virtual void Update()

    Implements

    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IDragHandler
    IInitializePotentialDragHandler
    IEventSystemHandler
    ICanvasElement
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)