zoukankan      html  css  js  c++  java
  • GUI闪烁效果[C#]

    重点是yield和StartCoroutine的使用

    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(true)
                    {
                            displaySysLabel = true;
                            yield return new WaitForSeconds(0.5f);
                            displaySysLabel = false;
                            yield return new WaitForSeconds(0.5f);
                    }
            }
            IEnumerator flashFriLabel()
            {
                    while(true)
                    {
                            displayFriLabel = true;
                            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 == true)
                    {
                            GUI.Label(new Rect(45,25,16,16),SysInfo,style);
                    }
                    GUI.Label(new Rect(61,25,16,16),"0",style);
                    if(displayFriLabel == true)
                    {
                            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();
            }
    }
    
  • 相关阅读:
    阿狸的打字机(bzoj 2434)
    Censoring(bzoj 3940)
    文本生成器(bzoj 1030)
    病毒(bzoj 2938)
    Road(bzoj 2750)
    codevs 2370 小机房的树
    HDU 2838 Cow Sorting
    luogu P2253 好一个一中腰鼓!
    hdu 1166 敌兵布阵
    luogu P1901 发射站
  • 原文地址:https://www.cnblogs.com/lm3515/p/1805324.html
Copyright © 2011-2022 走看看