Author Topic: Change button-background on active state  (Read 3999 times)

shadowdiver

  • Guest
Change button-background on active state
« on: May 02, 2013, 08:33:57 AM »
Hi,

how can i change the backgroundimage of an button, when it is clicked.

For example there is a menu like the build-menu of simcity. You click one of the buttons and it appears some sort of sub-menu. Now the clicked button looks different to the others. So you can see, you are in that special submenu.
An other simple example is a button to switch windowed-mode to full-screen and back. It is the same button but an other image you will see.

Is there something like:
  1. function OnClick() {
  2.     // do something special
  3.  
  4.     // change the backgroundimage of this button
  5. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change button-background on active state
« Reply #1 on: May 02, 2013, 08:42:16 AM »
Don't use a button. Create a sprite, add a collider to it (Alt+Shift+C), add a custom script to it that changes the sprite in OnClick.

shadowdiver

  • Guest
Re: Change button-background on active state
« Reply #2 on: May 04, 2013, 06:07:56 AM »
Quote
changes the sprite in OnClick
And how can i do that?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Change button-background on active state
« Reply #3 on: May 04, 2013, 12:15:59 PM »
  1. spritereference.spriteName = "TheNameOfTheNewSprite";