- Home /
How to make Image same size as UI Button
Hey guys so I made some code that is attached to a UI button in Unity. The Button works good and the code is fine. I designed an image that I would like to take the place of the button, so where it has the standard button img in the image script, I switched it for my own. The problem is, my image is smaller than the button was so when I make the img bigger, it also makes the clickable section of the button bigger (even though its invisible). So now, If i click the image it works but if I click the area surrounding the image, it still presses it. Is there a quick fix for this? should I just go into photoshop and make the image larger? Thanks everyone!
Answer by GeorgeCH · Dec 05, 2017 at 04:00 PM
@andrewwebber25 Yes, you will likely need to make the image bigger in Photoshop.
Alternatively, you can remove the button code and instead the Event System to achieve pretty much the same functionality without any resizing issues. In other words, you'd basically turn the button into a clickable image. To do so,
Remove the Button component
Add the EventTrigger component
Add the intended event types (PointerDown, PointerUp, or PointerClick)
Drag and drop the public method into its slot just as you normally would with the button
This also has the advantage of letting you fine-tune the behavior of the clickable image to a much greater extent - for example, you can program behaviors for when the mouse button is pressed and held, rather than just clicked.