• 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);
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    Linux/Unix中的#!和!#
    包含min函数的栈
    顺时针打印矩阵
    二叉树镜像
    数的子结构
    合并两个排序的链表
    反转链表
    链表中倒数第K个结点
    调整数组顺序使奇数位于偶数前面
    在O(1)时间删除链表结点
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609235.html
Copyright © 2020-2023  润新知