Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: AshB on January 09, 2013, 01:27:34 PM

Title: How to make a button switching different weapons ?
Post by: AshB 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..
   
Title: Re: How to make a button switching different weapons ?
Post by: ArenMook 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).
Title: Re: How to make a button switching different weapons ?
Post by: AshB 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 ?
Title: Re: How to make a button switching different weapons ?
Post by: Cripple 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.
Title: Re: How to make a button switching different weapons ?
Post by: AshB on January 12, 2013, 09:21:21 AM
Thanks,  I got it. Thnks for the reply.