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

[SOLVED] Button States - Is this possible?

Discussion in 'UGUI & TextMesh Pro' started by CelticKnight, Nov 19, 2016.

  1. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    Hello Guys,

    I am modifying a small project for a course I am doing. In the course we are using a UI canvas to create UI Text and adding a component from the UI elements to turn this text into a button and make them interactable, so, I thought why not try using a graphical button from the get go.

    Now, in the project I placed a small graphic button and is working with an OnClick function, but, what I would like to do is have the graphic button change when the mouse moves over the button and/or clicks on it, a bit like the onmouseover, onmouseout, and onclick states in HTML DOM so I can change the state of the button.

    I don't know whether this is possible in Unity and how much complexity would be involved. I am only a beginner!

    So, if anyone could point out if this is indeed possible? And if so, point me to some reference material to get started with it.

    Thankyou and Regards,
    CK.
     
  2. z3

    z3

    Joined:
    Jun 3, 2016
    Posts:
    34
    never tried it but theres a sprite swap in the button script in the inspector, click where it says color tint
     
  3. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    Oh right! Yep, found it and it does work!!!

    It's a bit of a pity that the button seems to "stay" in the down state after clicking and needs to be clicked elsewhere in the UI/game to get it to pop back up, is there any kind of simple workaround for that?
     
  4. JoaoPaul54

    JoaoPaul54

    Joined:
    Nov 20, 2013
    Posts:
    52
    I believe the usually accepted solution is to disable navigation on the buttons. If you do need to have this work with the keyboard then I'm not sure.
     
  5. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    Aha, right! Now, that works nicely :cool:

    Thanks so much for the input guys! It has allowed me to get the buttons looking and working great.

    Warmest Regards,
    CK.