Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted How to get if UI button is currently highlighted?

Discussion in 'Scripting' started by EpicMcDude, Oct 21, 2021.

  1. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    44
    Hi,

    Trying to figure out a simple way to know if a UI button is currently highlighted or not, this is for using a gamepad or keyboard, so I can't use OnPointerEnter or OnMouseOver methods or anything that exclusively uses a mouse.

    I'm not proficient in C#.

    I've been googling around but nothing seems to work so far -
    https://answers.unity.com/questions/1629490/checking-if-button-is-highlighted-with-a-controlle.html
    This one only works once the button is selected, not highlighted.

    https://docs.unity3d.com/2017.3/Documentation/ScriptReference/UI.Selectable.IsHighlighted.html
    This seems to be the closest thing to what I want, but I can't seem to make this work, I get the error "No overload method for "IsHighlighted" takes 1 arguments" and I have no idea how to fix it.

    Thank you!
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    633
    What's your code look like?
     
unityunity