Author Topic: How to make a button switching different weapons ?  (Read 2645 times)

AshB

  • Guest
How to make a button switching different weapons ?
« on: January 09, 2013, 01:27:34 PM »
Hi,   
I wanted to create a button that ll switch different weapon texturs and cylce between thm as i press thm. Is it possible to change texture of a button to different textures on every click ? or any other way to get switchable textures button ?
THNKS..
   

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button switching different weapons ?
« Reply #1 on: January 09, 2013, 03:28:46 PM »
A button is just a script that may or may not be referencing actual widgets.

In your case, you want to change the spriteName of the button's background (which is an actual widget).

AshB

  • Guest
Re: How to make a button switching different weapons ?
« Reply #2 on: January 10, 2013, 07:30:29 AM »
Thnks for the reply.
Can u tell me how to change the sprite of any button through script dynamically ?

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: How to make a button switching different weapons ?
« Reply #3 on: January 10, 2013, 08:37:51 AM »
Create a script and attach it to the UIButton. Cache the reference to the Background sprite (using GetComponentInChildren<> or directly in the editor) then implement the OnClick event. Change the name of the sprite using mySprite.spriteName it will update the sprite.
Graphicstream Dev.

AshB

  • Guest
Re: How to make a button switching different weapons ?
« Reply #4 on: January 12, 2013, 09:21:21 AM »
Thanks,  I got it. Thnks for the reply.