Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: MeDungeon on March 17, 2014, 07:03:30 AM

Title: UIButton changing color on Android issue
Post by: MeDungeon 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.  
Title: Re: UIButton changing color on Android issue
Post by: MeDungeon 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.
Title: Re: UIButton changing color on Android issue
Post by: ArenMook 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.