Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5415785
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: iOS平台

2015-08-31 17:44:04

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

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


编写TestButton.cs脚本:


[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
  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. }  

将脚本挂在simple button上



然后,运行:运行效果如下:

点击后,出现暂停按钮。


阅读(1170) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~