docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Selectable

    Simple selectable object - derived from to create a selectable control.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    UIBehaviour
    Selectable
    TMP_Dropdown
    TMP_InputField
    Button
    Dropdown
    InputField
    Scrollbar
    Slider
    Toggle
    Implements
    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IEventSystemHandler
    Inherited Members
    UIBehaviour.Start()
    UIBehaviour.OnDestroy()
    UIBehaviour.IsActive()
    UIBehaviour.OnRectTransformDimensionsChange()
    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)/Selectable", 35)]
    [ExecuteAlways]
    [SelectionBase]
    [DisallowMultipleComponent]
    public class Selectable : UIBehaviour, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IEventSystemHandler

    Constructors

    Selectable()

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

    Declaration
    protected Selectable()

    Fields

    m_CurrentIndex

    This selectable's index in the global s_Selectables array.

    Declaration
    protected int m_CurrentIndex
    Field Value
    Type Description
    int

    s_SelectableCount

    The number of active Selectable instances in s_Selectables.

    Declaration
    protected static int s_SelectableCount
    Field Value
    Type Description
    int

    s_Selectables

    Global array of all currently active Selectable instances.

    Declaration
    protected static Selectable[] s_Selectables
    Field Value
    Type Description
    Selectable[]

    Properties

    allSelectableCount

    How many selectable elements are currently active.

    Declaration
    public static int allSelectableCount { get; }
    Property Value
    Type Description
    int

    allSelectablesArray

    Copy of the array of all the selectable objects currently active in the scene.

    Declaration
    public static Selectable[] allSelectablesArray { get; }
    Property Value
    Type Description
    Selectable[]
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // required when using UI elements in scripts
    
    public class Example : MonoBehaviour
    {
        //Displays the names of all selectable elements in the scene
        public void GetNames()
        {
            foreach (Selectable selectableUI in Selectable.allSelectablesArray)
            {
                Debug.Log(selectableUI.name);
            }
        }
    }

    animationTriggers

    The AnimationTriggers for this selectable object.

    Declaration
    public AnimationTriggers animationTriggers { get; set; }
    Property Value
    Type Description
    AnimationTriggers
    Remarks

    Modifications will not be visible if transition is not Animation.

    animator

    Convenience function to get the Animator component on the GameObject.

    Declaration
    public Animator animator { get; }
    Property Value
    Type Description
    Animator
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class ExampleClass : MonoBehaviour
    {
        private Animator buttonAnimator;
        public Button button;
    
        void Start()
        {
            //Assigns the "buttonAnimator" with the button's animator.
            buttonAnimator = button.animator;
        }
    }

    colors

    The ColorBlock for this selectable object.

    Declaration
    public ColorBlock colors { get; set; }
    Property Value
    Type Description
    ColorBlock
    Remarks

    Modifications will not be visible if transition is not ColorTint.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class ExampleClass : MonoBehaviour
    {
        public Button button;
    
        void Start()
        {
            //Resets the colors in the buttons transitions.
            button.colors = ColorBlock.defaultColorBlock;
        }
    }

    currentSelectionState

    The current selection state of this Selectable.

    Declaration
    protected Selectable.SelectionState currentSelectionState { get; }
    Property Value
    Type Description
    Selectable.SelectionState

    image

    Convenience function that converts the referenced Graphic to a Image, if possible.

    Declaration
    public Image image { get; set; }
    Property Value
    Type Description
    Image

    interactable

    Is this object interactable.

    Declaration
    public bool interactable { get; set; }
    Property Value
    Type Description
    bool
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // required when using UI elements in scripts
    
    public class Example : MonoBehaviour
    {
        public Button startButton;
        public bool playersReady;
    
    
        void Update()
        {
            // checks if the players are ready and if the start button is useable
            if (playersReady == true && startButton.interactable == false)
            {
                //allows the start button to be used
                startButton.interactable = true;
            }
        }
    }

    navigation

    The Navigation setting for this selectable object.

    Declaration
    public Navigation navigation { get; set; }
    Property Value
    Type Description
    Navigation
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class ExampleClass : MonoBehaviour
    {
        public Button button;
    
        void Start()
        {
            //Set the navigation to the default value. ("Automatic" is the default value).
            button.navigation = Navigation.defaultNavigation;
        }
    }

    spriteState

    The SpriteState for this selectable object.

    Declaration
    public SpriteState spriteState { get; set; }
    Property Value
    Type Description
    SpriteState
    Remarks

    Modifications will not be visible if transition is not SpriteSwap.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class ExampleClass : MonoBehaviour
    {
        //Creates an instance of a sprite state (This includes the highlighted, pressed and disabled sprite.
        public SpriteState sprState = new SpriteState();
        public Button btnMain;
    
    
        void Start()
        {
            //Assigns the new sprite states to the button.
            btnMain.spriteState = sprState;
        }
    }

    targetGraphic

    Graphic that will be transitioned upon.

    Declaration
    public Graphic targetGraphic { get; set; }
    Property Value
    Type Description
    Graphic
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class ExampleClass : MonoBehaviour
    {
        public Image newImage;
        public Button btnMain;
    
        void SomeFunction()
        {
            //Displays the sprite transitions on the image when the transition to Highlighted,pressed or disabled is made.
            btnMain.targetGraphic = newImage;
        }
    }

    transition

    The type of transition that will be applied to the targetGraphic when the state changes.

    Declaration
    public Selectable.Transition transition { get; set; }
    Property Value
    Type Description
    Selectable.Transition
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // Required when Using UI elements.
    
    public class ExampleClass : MonoBehaviour
    {
        public Button btnMain;
    
        void SomeFunction()
        {
            //Sets the main button's transition setting to "Color Tint".
            btnMain.transition = Selectable.Transition.ColorTint;
        }
    }

    Methods

    AllSelectablesNoAlloc(Selectable[])

    Non allocating version for getting the all selectables. If selectables.Length is less then s_SelectableCount only selectables.Length elments will be copied which could result in a incomplete list of elements.

    Declaration
    public static int AllSelectablesNoAlloc(Selectable[] selectables)
    Parameters
    Type Name Description
    Selectable[] selectables

    The array to be filled with current selectable objects

    Returns
    Type Description
    int

    The number of element copied.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // required when using UI elements in scripts
    
    public class Example : MonoBehaviour
    {
        Selectable[] m_Selectables = new Selectable[10];
    
        //Displays the names of all selectable elements in the scene
        public void GetNames()
        {
            if (m_Selectables.Length < Selectable.allSelectableCount)
                m_Selectables = new Selectable[Selectable.allSelectableCount];
    
            int count = Selectable.AllSelectablesNoAlloc(ref m_Selectables);
    
            for (int i = 0; i < count; ++i)
            {
                Debug.Log(m_Selectables[i].name);
            }
        }
    }

    Awake()

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

    DoStateTransition(SelectionState, bool)

    Applies a visual state transition to the provided state.

    Declaration
    protected virtual void DoStateTransition(Selectable.SelectionState state, bool instant)
    Parameters
    Type Name Description
    Selectable.SelectionState state

    SelectionState to transition to

    bool instant

    Should the transition occur instantly, without animation.

    FindSelectable(Vector3)

    Finds the selectable object next to this one.

    Declaration
    public Selectable FindSelectable(Vector3 dir)
    Parameters
    Type Name Description
    Vector3 dir

    The direction in which to search for a neighbouring Selectable object.

    Returns
    Type Description
    Selectable

    The neighbouring Selectable object. Null if none found.

    Remarks

    The direction is determined by a Vector3 variable.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // required when using UI elements in scripts
    
    public class ExampleClass : MonoBehaviour
    {
        //Sets the direction as "Up" (Y is in positive).
        public Vector3 direction = new Vector3(0, 1, 0);
        public Button btnMain;
    
        public void Start()
        {
            //Finds and assigns the selectable above the main button
            Selectable newSelectable = btnMain.FindSelectable(direction);
    
            Debug.Log(newSelectable.name);
        }
    }

    FindSelectableOnDown()

    Find the selectable object below this one.

    Declaration
    public virtual Selectable FindSelectableOnDown()
    Returns
    Type Description
    Selectable

    The nearest Selectable below, or null.

    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 virtual Selectable FindSelectableOnLeft()
    Returns
    Type Description
    Selectable

    The nearest Selectable to the left, or null.

    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 virtual Selectable FindSelectableOnRight()
    Returns
    Type Description
    Selectable

    The nearest Selectable to the right, or null.

    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 virtual Selectable FindSelectableOnUp()
    Returns
    Type Description
    Selectable

    The nearest Selectable above, or null.

    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;
        }
    }

    InstantClearState()

    Clear any internal state from the Selectable (used when disabling).

    Declaration
    protected virtual void InstantClearState()

    IsHighlighted()

    Returns whether the selectable is currently 'highlighted' or not.

    Declaration
    public bool IsHighlighted()
    Returns
    Type Description
    bool

    Returns true if the element is highlighted; otherwise, returns false.

    Remarks

    Indicates whether the selectable UI element is currently highlighted.

    Examples
    //Create a UI element. To do this, go to Create > UI and select from the list. Attach this script to the UI GameObject to see it in action.
    
    using UnityEngine;
    using UnityEngine.UI;
    public class Example : MonoBehaviour
    {
        public Selectable selectable;
        // Check if the GameObject is being highlighted
        void Update()
        {
           if (selectable.IsHighlighted())
           {
                //Output that the GameObject was highlighted, or do something else
                Debug.Log("Selectable Highlighted");
            }
        }
    }

    IsInteractable()

    Is the object interactable.

    Declaration
    public virtual bool IsInteractable()
    Returns
    Type Description
    bool

    True if this Selectable is interactive.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // required when using UI elements in scripts
    
    public class Example : MonoBehaviour
    {
        public Button startButton;
    
        void Update()
        {
            if (!startButton.IsInteractable())
            {
                Debug.Log("Start Button has been Disabled");
            }
        }
    }

    IsPressed()

    Returns true if the element is being pressed; otherwise, returns false.

    Declaration
    public bool IsPressed()
    Returns
    Type Description
    bool

    Returns true if the element is pressed; otherwise, returns false.

    Remarks

    Indicates whether the selectable UI element is currently pressed.

    Examples
    //Create a UI element. To do this, go to Create > UI and select from the list. Attach this script to the UI GameObject to see it in action.
    
    using UnityEngine;
    using UnityEngine.UI;
    public class Example : MonoBehaviour
    {
        public Selectable selectable;
        // Check if the GameObject is being pressed.
        void Update()
        {
            if (selectable.IsPressed())
            {
                Debug.Log("Selectable Pressed");
            }
        }
    }

    OnCanvasGroupChanged()

    Called when a parent CanvasGroup changes. Re-evaluates the interactable state.

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

    OnDeselect(BaseEventData)

    Unset selection and transition to appropriate state.

    Declaration
    public virtual void OnDeselect(BaseEventData eventData)
    Parameters
    Type Name Description
    BaseEventData eventData

    The base event data.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, IDeselectHandler //This Interface is required to receive OnDeselect callbacks.
    {
        public void OnDeselect(BaseEventData data)
        {
            Debug.Log("Deselected");
        }
    }

    OnDidApplyAnimationProperties()

    Called when animation properties are applied. Triggers a state transition.

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

    OnDisable()

    Called when it becomes disabled. Unregisters from the global selectable list and clears pointer state.

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

    OnEnable()

    Called when it becomes enabled. Registers in the global selectable list and performs an initial state transition.

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

    OnMove(AxisEventData)

    Determine in which of the 4 move directions the next selectable object should be found.

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

    The axis event data containing the move direction.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, IMoveHandler
    {
        //When the focus moves to another selectable object, Invoke this Method.
        public void OnMove(AxisEventData eventData)
        {
            //Assigns the move direction and the raw input vector representing the direction from the event data.
            MoveDirection moveDir = eventData.moveDir;
            Vector2 moveVector = eventData.moveVector;
    
            //Displays the information in the console
            Debug.Log(moveDir + ", " + moveVector);
        }
    }

    OnPointerDown(PointerEventData)

    Called when the pointer is pressed. Evaluates the current selection state and transitions to the appropriate state.

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

    The pointer event data for the press.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, IPointerDownHandler// required interface when using the OnPointerDown method.
    {
        //Do this when the mouse is clicked over the selectable object this script is attached to.
        public void OnPointerDown(PointerEventData eventData)
        {
            Debug.Log(this.gameObject.name + " Was Clicked.");
        }
    }

    OnPointerEnter(PointerEventData)

    Evaluate current state and transition to appropriate state. New state could be pressed or hover depending on pressed state.

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

    The pointer event data for the enter.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, IPointerEnterHandler// required interface when using the OnPointerEnter method.
    {
        //Do this when the cursor enters the rect area of this selectable UI object.
        public void OnPointerEnter(PointerEventData eventData)
        {
            Debug.Log("The cursor entered the selectable UI element.");
        }
    }

    OnPointerExit(PointerEventData)

    Evaluate current state and transition to normal state.

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

    The pointer event data for the exit.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, IPointerExitHandler// required interface when using the OnPointerExit method.
    {
        //Do this when the cursor exits the rect area of this selectable UI object.
        public void OnPointerExit(PointerEventData eventData)
        {
            Debug.Log("The cursor exited the selectable UI element.");
        }
    }

    OnPointerUp(PointerEventData)

    Called when the pointer is released. Evaluates the eventData and transitions to appropriate state.

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

    The pointer event data for the release.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, IPointerUpHandler, IPointerDownHandler// These are the interfaces the OnPointerUp method requires.
    {
        //OnPointerDown is also required to receive OnPointerUp callbacks
        public void OnPointerDown(PointerEventData eventData)
        {
        }
    
        //Do this when the mouse click on this selectable UI object is released.
        public void OnPointerUp(PointerEventData eventData)
        {
            Debug.Log("The mouse click was released");
        }
    }

    OnSelect(BaseEventData)

    Set selection and transition to appropriate state.

    Declaration
    public virtual void OnSelect(BaseEventData eventData)
    Parameters
    Type Name Description
    BaseEventData eventData

    The base event data.

    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour, ISelectHandler// required interface when using the OnSelect method.
    {
        //Do this when the selectable UI object is selected.
        public void OnSelect(BaseEventData eventData)
        {
            Debug.Log(this.gameObject.name + " was selected");
        }
    }

    OnTransformParentChanged()

    Called when the parent changes. Re-evaluates interactability based on parent CanvasGroups.

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

    OnValidate()

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

    Reset()

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

    Select()

    Selects this Selectable.

    Declaration
    public virtual void Select()
    Examples
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI; // required when using UI elements in scripts
    using UnityEngine.EventSystems;// Required when using Event data.
    
    public class ExampleClass : MonoBehaviour// required interface when using the OnSelect method.
    {
        public InputField myInputField;
    
        //Do this OnClick.
        public void SaveGame()
        {
            //Makes the Input Field the selected UI Element.
            myInputField.Select();
        }
    }

    Implements

    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IEventSystemHandler
    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)