查看: 1306|回复: 3
打印 上一主题 下一主题

Unity3D中制作GUI闪烁效果,主要是yield的使用

[复制链接]

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

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

跳转到指定楼层
楼主
发表于 2012-7-27 17:00:22 |只看该作者 |倒序浏览
U吧以前好像有发过一篇关于重复函数的使用,下面再转帖一篇,来个具体的应用例子!
以下为转帖内容:
重点是yield和StartCoroutine的使用

水平有限,多多包涵
代码为:c#编写
using UnityEngine;

using System.Collections;
public class MainBoardTop : MonoBehaviour

{

        public Texture2D Logo;

        public Texture2D SysInfo;

        public Texture2D FriInfo;

        public Texture2D IcoHelp;

        public GUIStyle style;

        public GUIStyle pathStyle;

        private bool displaySysLabel = false;

        private bool displayFriLabel = false;

        IEnumerator Start()

        {

                yield return StartCoroutine(flashSysLabel());

                yield return StartCoroutine(flashFriLabel());

        }

        IEnumerator flashSysLabel()

        {

                while(***e)

                {

                        displaySysLabel = ***e;

                        yield return new WaitForSeconds(0.5f);

                        displaySysLabel = false;

                        yield return new WaitForSeconds(0.5f);

                }

        }

        IEnumerator flashFriLabel()

        {

                while(***e)

                {

                        displayFriLabel = ***e;

                        yield return new WaitForSeconds(0.5f);

                        displayFriLabel = false;

                        yield return new WaitForSeconds(0.5f);

                }

        }

        void OnGUI()

        {

                GUI.BeginGroup(new Rect(0, 0, 300, 100));

                GUI.Button(new Rect(3,5,37,37),Logo,style);

                GUI.Button(new Rect(45,8,150,15),"test",pathStyle);

                if(displaySysLabel == ***e)

                {

                        GUI.Label(new Rect(45,25,16,16),SysInfo,style);

                }

                GUI.Label(new Rect(61,25,16,16),"0",style);

                if(displayFriLabel == ***e)

                {

                        GUI.Label(new Rect(77,25,16,16),FriInfo,style);

                }

                GUI.Label(new Rect(93,25,16,16),"0",style);

                GUI.Label(new Rect(108,25,16,16),IcoHelp,style);

                GUI.EndGroup();

        }

}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

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

沙发
发表于 2012-8-3 18:01:51 |只看该作者
我爱纳金网~www.narkii.com
回复

使用道具 举报

Zack    

459

主题

1

听众

5478

积分

高级设计师

Rank: 6Rank: 6

纳金币
5531
精华
0

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

板凳
发表于 2012-11-25 20:19:42 |只看该作者
学习了。谢谢!
回复

使用道具 举报

may    

8830

主题

81

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52344
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

地板
发表于 2012-11-27 03:02:00 |只看该作者
lZ的回复很不错,支持!
回复

使用道具 举报

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

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

GMT+8, 2025-7-22 00:56 , Processed in 0.137229 second(s), 29 queries .

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

© 2008-2019 Narkii Inc.

回顶部