Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

UI.Button.IsHighlighted <-- How does a guy like me make this work?

Discussion in 'UGUI & TextMesh Pro' started by infinitypbr, Sep 8, 2014.

  1. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    I'd like to know if a button is currently selected, so I think the "IsHighlighted" function is proper to use.

    But i can't seem to figure out how to make it work. I'm using UnityScript, and the code below is certainly wrong, but it's what I've got right now. I'm not sure how to put in the event system into the function.

    Anyone know?

    THANKS!

    Code (csharp):
    1. if (GetComponent(UI.Button).IsHighlighted(eventData : EventSystems.BaseEventData.selectedObject))
    2. print (name + "waspressed");
     
  2. technicalfiction

    technicalfiction

    Joined:
    Jan 31, 2014
    Posts:
    12
    I have been having the same problem - I would appreciate an answer. When you try to type in IsHighlighted, it does not auto complete in mine. It says it is a protected function - but since you are using an instance of Button that should not matter. Hmm.
     
    SlavDubit likes this.
  3. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    maybe try something like this
    Code (csharp):
    1.  
    2. if(gameObject == EventSystem.current.currentSelectedGameObject)  {
    3.    Debug.Log(" we're selected! " );
    4. }
    5.  
     
    technicalfiction likes this.
  4. technicalfiction

    technicalfiction

    Joined:
    Jan 31, 2014
    Posts:
    12
    Thanks. Yeah, I need to read up more on the EventSystem functionality bc I have no idea how that all works