纳金网

标题: Unity3D中制作GUI闪烁效果,主要是yield的使用 [打印本页]

作者: 她。    时间: 2012-7-27 17:00
标题: Unity3D中制作GUI闪烁效果,主要是yield的使用
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();

        }

}
作者: 她。    时间: 2012-8-3 18:01
我爱纳金网~www.narkii.com
作者: Zack    时间: 2012-11-25 20:19
学习了。谢谢!
作者: may    时间: 2012-11-27 03:02
lZ的回复很不错,支持!




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5