• unity中实现三个Logo图片进行3秒钟的若隐若现后互相切换Logo图片


        private List<Sprite> storeTexture;
        public void Start()
        {
            storeTexture = new List<Sprite>();
            storeTexture.Clear();
            //加载图片并储存在List中
            Sprite texture1 = Resources.Load<Sprite>("Textures/one");
            storeTexture.Add(texture1);
            Sprite texture2 = Resources.Load<Sprite>("Textures/two");
            storeTexture.Add(texture2);
            Sprite texture3 = Resources.Load<Sprite>("Textures/3");
            storeTexture.Add(texture3);
            //遍历List中物体并打印出名字
            foreach (var kk in storeTexture)
            {
                Debug.LogError(kk.name);
            }
        }
        private float Timer = 0;
        private float value = 3;
        public void Update()
        {
            //Logo1从透明变为不透明状态
            if (logoSwtich == LogoSwtich.Start)
            {
                Timer += Time.deltaTime / value;
                logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
                if (Timer >= 1)
                {
                    logoSwtich = LogoSwtich.DeleteLogo1Alpha;
                }
            }
            //Logo1从不透明变为透明状态
            if (logoSwtich == LogoSwtich.DeleteLogo1Alpha)
            {
                Timer -= Time.deltaTime / value;
                logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
                if (Timer <= 0)
                {
                    logoSwtich = LogoSwtich.ChangeLogo2;
                }
            }
            //将Logo1更换为Logo2
            if (logoSwtich == LogoSwtich.ChangeLogo2)
            {
                logo.GetComponent<Image>().sprite = storeTexture[1];
                logoSwtich = LogoSwtich.AddLogo2Alpha;
            }
            //Logo2从透明变为不透明状态
            if (logoSwtich == LogoSwtich.AddLogo2Alpha)
            {
                Timer += Time.deltaTime / value;
                logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
                if (Timer >= 1)
                {
                    logoSwtich = LogoSwtich.DeleteLogo2Alpha;
                }
            }
            //Logo1从不透明变为透明状态
            if (logoSwtich == LogoSwtich.DeleteLogo2Alpha)
            {
                Timer -= Time.deltaTime / value;
                logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
                if (Timer <= 0)
                {
                    logoSwtich = LogoSwtich.ChangeLogo3;
                }
            }
            //将Logo2更换为Logo3
            if (logoSwtich == LogoSwtich.ChangeLogo3)
            {
                logo.GetComponent<Image>().sprite = storeTexture[2];
                logoSwtich = LogoSwtich.AddLogo3Alpha;
            }
            //Logo3从透明变为不透明状态
            if (logoSwtich == LogoSwtich.AddLogo3Alpha)
            {
                Timer += Time.deltaTime / value;
                logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
                if (Timer >= 1)
                {
                    logoSwtich = LogoSwtich.DeleteLogo3Alph;
                }
            }
            //Logo3从不透明变为透明状态
            if (logoSwtich == LogoSwtich.DeleteLogo3Alph)
            {
                Timer -= Time.deltaTime / value;
                logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
                if (Timer <= 0)
                {
                    logoSwtich = LogoSwtich.ChangeLogo1;
                }
            }
            //将Logo3更换为Logo1
            if (logoSwtich == LogoSwtich.ChangeLogo1)
            {
                logo.GetComponent<Image>().sprite = storeTexture[0];
                logoSwtich = LogoSwtich.Start;
            }
        }
      LogoSwtich logoSwtich = LogoSwtich.Start;
        //Logo图片切换状态
        public enum LogoSwtich
        {
            Start,
            DeleteLogo1Alpha,
            ChangeLogo2,
            AddLogo2Alpha,
            DeleteLogo2Alpha,
            ChangeLogo3,
            AddLogo3Alpha,
            DeleteLogo3Alph,
            ChangeLogo1,
            End
        }

    unity中使用Image组件更换Logo图片属性如下:
    1、sprite     用来渲染图像的精灵。

    2、overrideSprite  设置用于呈现的覆盖精灵,设置为null将恢复默认的srpite。

    unity中使用RawImage组件更换图片属性是  texture  (RawImage的纹理)

  • 相关阅读:
    做正确的事,正确的做事
    博客园翻车启示录
    从一次线下读书会获得的收获
    坚持一个好习惯该有多难?
    有道云笔记
    Leetcode 10. 正则表达式匹配
    C++版
    VS 2013 professional版在win10上安装出错的解决方法
    华为校招2016.09机试 第1题: 字符串按指定长度重新分割
    C#版
  • 原文地址:https://www.cnblogs.com/Study088/p/7694647.html
Copyright © 2020-2023  润新知