Author Topic: UIButton changing color on Android issue  (Read 3346 times)

MeDungeon

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
UIButton changing color on Android issue
« on: March 17, 2014, 07:03:30 AM »
I'm trying to change button color and it works just fine in Editor, but on Android device it requires two clicks instead of one to change color. Any advice?
The code I'm using:

  1.         void OnClick()
  2.         {
  3.                 button.defaultColor = Color.white;
  4.                 sprite.color = Color.white;
  5.         }
  6.  
  7.  

MeDungeon

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIButton changing color on Android issue
« Reply #1 on: March 17, 2014, 07:55:15 AM »
Well, figured out a solution by myself.
The problem is in UIButton transition property, if I delay changing color for that amount of time (0.2f by default) everything works.
It seems like a bug, even in editor, if you manage to remove mouse from button faster than transition finished (which is always the case on mobile) - new color will not be applied until mouse will hover button again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton changing color on Android issue
« Reply #2 on: March 17, 2014, 11:54:41 AM »
Once a tween color begins, it uses the sprite's starting color as well as the target color. You're changing the default color and the sprite's color, but if there is already a tween active, it will overwrite the values. GetComponent<TweenColor>() and update its 'to' and 'from' values if you're changing things inside OnClick like that.