Search Unity

Change mouse cursor when element under it is clickable.

Discussion in 'UGUI & TextMesh Pro' started by eyalm, May 26, 2017.

  1. eyalm

    eyalm

    Joined:
    Dec 20, 2015
    Posts:
    42
    I want to change the cursor of the mouse when ever the mouse position is hovering above a clickable UI element.

    I'v found some solutions but all of them i using the update function and iteration over a list or hovered gameObjects.

    So my question is:
    why isn't there an event that just called with the currently hovered AND clickable element?
    like: OnPointerEnter(GameObject hoveredGameObject);

    Just like there are "enter" and "exit" events on each monobehavior, aren't those objects are stored anywhere?

    This is just weird I have to look for it with the update function and and use iterations for simply changing the mouse cursor.

    Is there any better solution that I've missed?
     
  2. Donay

    Donay

    Joined:
    Apr 28, 2017
    Posts:
    70
    Not done it before so not sure if this is what you need.
    Can you add the event you want on the UI element from the inspector?
    Add component/Event/Event Trigger
    Add New Event Type
     
  3. eyalm

    eyalm

    Joined:
    Dec 20, 2015
    Posts:
    42
    The problem here is that you need to implement it on every clickable element in the game.
    I want something universal for all UI elements that are clickable in the game.
    Like override the function that calls the functions on the UI element.
     
    MilenaRocha likes this.
  4. Donay

    Donay

    Joined:
    Apr 28, 2017
    Posts:
    70
    True, but better than using an update function.
    You could add it to a script startup, and attach the script to the UI elements you want to behave in this way.
    If it’s all UI elements you could add the Event Trigger at scene load to all UI elements.
    You could look at extending the UI elements but others have expressed some functionality issue with this
     
  5. eyalm

    eyalm

    Joined:
    Dec 20, 2015
    Posts:
    42
    Well I'v found myself doing the script on each UI element option.

    It is still kinda weird that I need to do that simply to swap the mouse cursor to clickable which is pretty standard feature if you ask me...

    Thanks for the help.
     
    MilenaRocha likes this.