1. 程式人生 > >unity中實現三個Logo圖片進行3秒鐘的若隱若現後互相切換Logo圖片

unity中實現三個Logo圖片進行3秒鐘的若隱若現後互相切換Logo圖片

date += srp val logs ima 精靈 texture 透明

    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的紋理)

unity中實現三個Logo圖片進行3秒鐘的若隱若現後互相切換Logo圖片