Author Topic: image buttons  (Read 6530 times)

peterc

  • Guest
image buttons
« on: June 18, 2012, 11:38:28 PM »
I’ve defined an image button and assigned the same texture to both "hover" and "pressed". I have two questions:

  • When I hover the mouse pointer over the image button, the image size changes (it doubles in size). Has anyone else experienced this?
  • I want the image to permanently change to a different image after I click on it. How can I change the image tied to the image button from within my OnClick() code?

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: image buttons
« Reply #1 on: June 19, 2012, 01:22:27 AM »
1. It is because there is a UIButton Offset script attached to the button. You should turn it off or change the resize values.

2. Yes.

You could do something (similar) to this using GetComponent.

mymenugui.GetComponentsInChildren<UISprite>()[0].spriteName = "image_name";

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: image buttons
« Reply #2 on: June 19, 2012, 12:12:10 PM »
I just created an image button using the same sprite for all 3 states and the sprite doesn't change or grow in any way when I click on it. Check what else you have attached to your image button.

UIImageButton has properties you can set in code as well:

  1.         public string normalSprite;
  2.         public string hoverSprite;
  3.         public string pressedSprite;

peterc

  • Guest
Re: image buttons
« Reply #3 on: June 20, 2012, 07:39:13 AM »
Thanks guys, both issues are fixed now. I worked out how to change the image by looking at UIImageButton - it's pretty straightforward.

Re the resize-on-hover problem: I didn't have a UIButton Offset script attached, but I rebuilt my atlas and that seems to have somehow fixed the issue. So all is good.  :)