zoukankan      html  css  js  c++  java
  • 改变图片透明度

    ///模型从不透明变成透明直至消失
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class TestClass : MonoBehaviour
    {
        private float tempTime;
        public GameObject StartBtn;
        bool _Check = false;
        Shader shader;
    
        void Start()
        {
            shader = Shader.Find("Transparent/Diffuse");
            this.GetComponent<Renderer>().material.shader=shader;
            StartBtn.GetComponent<Button>().onClick.AddListener(delegate
            {
                _Check = true;
            });
            tempTime = 0;
            //获取材质本来的属性  
            this.GetComponent<Renderer>().material.color = new Color
            (
                    this.GetComponent<Renderer>().material.color.r,
                    this.GetComponent<Renderer>().material.color.g,
                    this.GetComponent<Renderer>().material.color.b,
                    //需要改的就是这个属性:Alpha值  
                    this.GetComponent<Renderer>().material.color.a
            );
        }
        void Update()
        {
            if (_Check)
            {
                if (tempTime < 1)
                {
                    tempTime = tempTime + Time.deltaTime;
                }
                if (this.GetComponent<Renderer>().material.color.a <= 1)
                {
                    this.GetComponent<Renderer>().material.color = new Color
                    (
                        this.GetComponent<Renderer>().material.color.r,
                        this.GetComponent<Renderer>().material.color.g,
                        this.GetComponent<Renderer>().material.color.b,
    
    
                    //减小Alpha值,从1-30秒逐渐淡化 ,数值越大淡化越慢 
                    gameObject.GetComponent<Renderer>().material.color.a - tempTime / 20 * Time.deltaTime
                    );
                }
                Destroy(this.gameObject, 20.0f);//40秒后消除
            }
        }
    }
  • 相关阅读:
    C/C++内存对齐
    Fibonacci
    Count 1 in Binary
    Hash Function
    Fast Power
    Update Bits
    Unique Binary Search Trees
    Java知识体系(持续更新)
    如何发现牛股
    OpenResty究竟解决了什么痛点
  • 原文地址:https://www.cnblogs.com/Cocomo/p/7088089.html
Copyright © 2011-2022 走看看