Author Topic: Change the default color of a button  (Read 6108 times)

laurentl

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 188
    • View Profile
    • McDROID
Change the default color of a button
« on: May 22, 2013, 07:26:16 PM »
In the map, each zone is a button and changes color.
The color of each zone changes with progress.
I am changing the default color of the button
ch.GetComponent<UIButton>().defaultColor = completionColors
  • ;

When I hover or click the button it defaults back to the default color of the button on awake.

What do I need to do instead?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change the default color of a button
« Reply #1 on: May 22, 2013, 09:39:39 PM »
defaultColor is set in Start() using the color of the sprite pointed to by UIButton. Modifying "defaultColor" changes this value, and it does not get reverted, so I have no idea what's changing yours to something else. Keep in mind, this is the default color -- as in, the color of the button when mouse is not hovering over it, and it's not pressed.

laurentl

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 188
    • View Profile
    • McDROID
Re: Change the default color of a button
« Reply #2 on: May 23, 2013, 09:01:47 PM »
My code clearly changes the default color, no nullref error in the console so I don't know what is happening.

  1.        
  2. void SwitchToColor (UISprite sprite, COMPLETION c)
  3. {
  4.         TweenColor.Begin (sprite.gameObject, 1f, completionColors [(int)c]);
  5.         sprite.GetComponent<UIButton> ().defaultColor = completionColors [(int)c];
  6. }
  7.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change the default color of a button
« Reply #3 on: May 23, 2013, 09:08:32 PM »
What is "sprite"? Is it a part of the button? The same sprite the button tweens, perhaps?

Setting "defaultColor" before the tween ever started won't have any effect as it gets overwritten in the Start() function.

laurentl

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 188
    • View Profile
    • McDROID
Re: Change the default color of a button
« Reply #4 on: May 23, 2013, 09:35:22 PM »
Yes the sprite is part of the button and that sprite gets tweened by the button on over.
Maybe there is a Button that doesn't tween color but I didn't find one, I only need to show that over is registered to show that this is a button.

As for default getting overwritted in Start, you have some code that works for you?