zoukankan      html  css  js  c++  java
  • UI界面之淡入淡出

    1.
    using
    UnityEngine; using System.Collections; using UnityEngine.UI; public class danrudanchu : MonoBehaviour { public Image image; public float showTime = 10;//10秒换一次 public float ShowTimeTrigger = 0;//计时 public float fadeTime = 3; public float fadeTimeTrigger = 0; private bool show = true; // Use this for initialization void Start() { } // Update is called once per frame void Update() { ShowTimeTrigger += Time.deltaTime;//计时 if (ShowTimeTrigger > showTime) { if (fadeTimeTrigger >= 0 && fadeTimeTrigger <fadeTime) { fadeTimeTrigger += Time.deltaTime; if (show) { image.color = new Color(1, 1, 1, 1 - (fadeTimeTrigger / fadeTime)); } else { image.color = new Color(1, 1, 1, (fadeTimeTrigger / fadeTime)); } } else { fadeTimeTrigger = 0; ShowTimeTrigger = 0; if (show) { show = false; } else { show = true; } } } } }

    2.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class danruchu : MonoBehaviour {
        public Image image;
        public float showTime = 3;//3秒换一次
        public float starttime = 0;//计时
        public float time = 0;
        bool b = true;
        // Use this for initialization
        void Start () {
            
        }
        
        // Update is called once per frame
        void Update () {
            starttime+= Time.deltaTime;
            if (starttime > showTime)
            {
                if (time >= 0 && time < 1)
                {
                    time += Time.deltaTime;
                    if (b)
                    {
                    image.color = new Color(1, 1, 1, 1 - time);
                    }
                    else
                    {
                        image.color = new Color(1, 1, 1, time);
                    }
                }
                else
                {
                    time = 0;
                    starttime = 0;
                    if (b)
                    {
                        b = false;
    
                    }
                    else
                    {
                        b = true;
                    }
                }
            }
           
        }
    }

    3.

    这也可以淡入淡出:
    //this.gameObject.GetComponent<Image>().CrossFadeAlpha(0, 5, false);
            GetComponent<Image>().CrossFadeColor(new Color(1, 1, 1, 0), 5, true, true);
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    [leetcode-648-Replace Words]
    [leetcode-647-Palindromic Substrings]
    [leetcode-646-Maximum Length of Pair Chain]
    [leetcode-645-Set Mismatch]
    [leetcode-459-Repeated Substring Pattern]
    [leetcode-636-Exclusive Time of Functions]
    [leetcode-644-Maximum Average Subarray II]
    iOS开发之使用XMPPFramework实现即时通信(三)
    Oracle 内置sql函数大全
    Oracle 中的sql函数以及分页
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609235.html
Copyright © 2011-2022 走看看