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

Button Test

Discussion in '2D' started by TheStache, May 29, 2014.

  1. TheStache

    TheStache

    Joined:
    May 29, 2014
    Posts:
    2
    For a test in Unity, I would like to make a Button in 2D that can be clicked, has multiple states when moused over, clicked, etc, and plays a sound when clicked, but I'm not very experienced and can't figure out how to get it to do these things, though I do understand the basics of making it "clickable." Can anybody help?
     
  2. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    Hi at first you need to add collider to your sprite, then you can listen to the following events:
    * OnMouseDown
    * OnMouseOver
    * OnMouseUp

    and change the sprite of the button accordingly. Besides that even if you dont want to listen to so many events there is a tool which does so: http://www.tasharen.com/?page_id=140
     
  3. TheStache

    TheStache

    Joined:
    May 29, 2014
    Posts:
    2
    Thanks, but what about having it play a sound when pressed?
     
  4. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    You need to add Audio Source component to the button.