Search Unity

Button component on sprite object

Discussion in 'UGUI & TextMesh Pro' started by BerkayD, Dec 15, 2014.

  1. BerkayD

    BerkayD

    Joined:
    Sep 28, 2014
    Posts:
    3
    Hi, i am making a 2D game. I want to add "Button" component to sprite object in world, so i can use it as a button. I want to use the component's "OnClick" function instead of Raycasting or OnMouseDown functions.
    "OnClick" will make it much more easier for me.
    So i tried to add Button component, but it didn't work. I tried to add Box collider but nothing changed. Is it possible to use "Button" compoenent outside of GUI?
    If so, what should i do? If not, is there a way that i can use "OnClick" function, in my gameboject? Or, do i have to use RayCasting or OnMouseDown function to use my sprite as a button?
    -Thank you^^
     

    Attached Files:

    ucaduque likes this.
  2. highlyinteractive

    highlyinteractive

    Joined:
    Sep 6, 2012
    Posts:
    116
  3. BerkayD

    BerkayD

    Joined:
    Sep 28, 2014
    Posts:
    3
  4. ReckTy

    ReckTy

    Joined:
    Jan 21, 2018
    Posts:
    3
    Very late but I hope I can help someone.
    If you add an Image component to your sprite "Object" and then add a Button component, you'll have a button that works properly. :)

    Also, drag the Image component to "Button>Target Graphic" if it's not added already.
    + Add your sprite to the Image component and delete/disable the Sprite Renderer component.

    12d44bb3e58c92344bfda14471237632.png
     
    Last edited: Feb 4, 2018
  5. joshstahl

    joshstahl

    Joined:
    Mar 23, 2017
    Posts:
    1
    Yes you helped me!
    Great explanation!
     
  6. drewwlewis

    drewwlewis

    Joined:
    Oct 1, 2020
    Posts:
    1
    I have been pulling my hair out all day trying to figure out what I was doing wrong. I never thought it was an image component I was missing. 2 year later still helping people.
     
  7. ReckTy

    ReckTy

    Joined:
    Jan 21, 2018
    Posts:
    3
    I completely forgot, I ever used this forum.
    Glad to see I could help someone, though!
     
    tom41_10tt and Hromad_a like this.
  8. cjcleveland08

    cjcleveland08

    Joined:
    May 27, 2019
    Posts:
    1
    It wont work for me? nothing happens and i did everything