图片切换

我们接着上一个例子,做一个按钮的图片切换。

功能,就像播放器的“开始”和“暂停”。

1.using UnityEngine;  
2.using System.Collections;  
3.  
4.public class TestButton : MonoBehaviour {  
5.    protected bool switchFlag = true;  
6.  
7.    // Use this for initialization  
8.    void Start () {  
9.      
10.    }  
11.  
12.    void OnClick () {  
13.        if (this.switchFlag) {  
14.            this.GetComponent<UISprite> ().spriteName = "pause";  
15.            this.GetComponent<UIButton> ().normalSprite = "pause";  
16.            this.switchFlag = false;  
17.        }  
18.        else{  
19.            this.GetComponent<UISprite>().spriteName = "start";  
20.            this.GetComponent<UIButton>().normalSprite = "start";  
21.            this.switchFlag = true;  
22.        }  
23.    }  
24.} 

 

posted on 2015-08-14 09:21  public_void_digua  阅读(173)  评论(0)    收藏  举报

导航