Search Unity

Button component on sprite object

Discussion in 'Unity UI (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:
    92
  3. BerkayD

    BerkayD

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

    ReckTy

    Joined:
    Jan 21, 2018
    Posts:
    1
    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
    joshstahl likes this.
  5. joshstahl

    joshstahl

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