Tribute to the original http://blog.csdn.net/chenggong2dm/article/details/25716309
Let's go on to an example and make a button image switch.
Functions, like the "Start" and "pause" of the player.
To write the TestButton.cs script:
[CSharp]View Plaincopy
- Using Unityengine;
- Using System.Collections;
- Public class Testbutton:monobehaviour {
- protected bool Switchflag = true;
- // Use this for initialization
- void Start () {
- }
- void OnClick () {
- if (this.switchflag) {
- This . Getcomponent<uisprite> (). Spritename = "Pause";
- This . Getcomponent<uibutton> (). Normalsprite = "Pause";
- This.switchflag = false;
- }
- else{
- This . Getcomponent<uisprite> (). Spritename = "Start";
- This . Getcomponent<uibutton> (). Normalsprite = "Start";
- This.switchflag = true;
- }
- }
- }
To hang a script on a simple button
Then, run: Run the effect as follows:
When clicked, a Pause button appears.
NGUI 3.5 Tutorial (V) button-image toggle