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);
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    从原理层面掌握@InitBinder的使用【享学Spring MVC】
    array详解
    forward_list详解
    list详解
    deque详解
    vector详讲(三)实例
    vector详讲(二)迭代器
    vector详讲(一)
    numeric_limits<>函数
    seek()和tell()在文件里转移
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609235.html
Copyright © 2011-2022 走看看