查看: 527|回复: 0
打印 上一主题 下一主题

[其他] GUI闪烁效果的实现

[复制链接]

711

主题

10

听众

5805

积分

高级设计师

Rank: 6Rank: 6

纳金币
2954
精华
3

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2015-7-30 00:13:23 |只看该作者 |倒序浏览
GUI闪烁效果的实现
  1. using UnityEngine;
  2.         using System.Collections;
  3. //         重点是yield和StartCoroutine的使用。
  4.         public class MainBoardTop : MonoBehaviour
  5.         {
  6.                 public Texture2D Logo;
  7.                 public Texture2D SysInfo;
  8.                 public Texture2D FriInfo;
  9.                 public Texture2D IcoHelp;
  10.                 public GUIStyle style;
  11.                 public GUIStyle pathStyle;
  12.                 private bool displaySysLabel = false;
  13.                 private bool displayFriLabel = false;
  14.                 IEnumerator Start()
  15.                 {
  16.                         yield return StartCoroutine(flashSysLabel());
  17.                         yield return StartCoroutine(flashFriLabel());
  18.                 }
  19.                 IEnumerator flashSysLabel()
  20.                 {
  21.                         while(true)
  22.                         {
  23.                                 displaySysLabel = true;
  24.                                 yield return new WaitForSeconds(0.5f);
  25.                                 displaySysLabel = false;
  26.                                 yield return new WaitForSeconds(0.5f);
  27.                         }
  28.                 }
  29.                 IEnumerator flashFriLabel()
  30.                 {
  31.                 while(true)
  32.                         {
  33.                                 displayFriLabel = true;
  34.                                         yield return new WaitForSeconds(0.5f);
  35.                                 displayFriLabel = false;
  36.                                 yield return new WaitForSeconds(0.5f);
  37.                         }
  38.                 }
  39.                 void OnGUI()
  40.                 {
  41.                         GUI.BeginGroup(new Rect(0, 0, 300, 100));
  42.                         GUI.Button(new Rect(3,5,37,37),Logo,style);
  43.                         GUI.Button(new Rect(45,8,150,15),"test",pathStyle);
  44.                         if(displaySysLabel == true)
  45.                         {
  46.                                 GUI.Label(new Rect(45,25,16,16),SysInfo,style);
  47.                         }
  48.                         GUI.Label(new Rect(61,25,16,16),"0",style);
  49.                         if(displayFriLabel == true)                        {
  50.                                 GUI.Label(new Rect(77,25,16,16),FriInfo,style);
  51.                         }
  52.                         GUI.Label(new Rect(93,25,16,16),"0",style);
  53.                         GUI.Label(new Rect(108,25,16,16),IcoHelp,style);
  54.                         GUI.EndGroup();
  55.                 }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-8-10 21:48 , Processed in 0.068123 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部