绑定在需要淡入淡出的物体上就能直接使用
通过修改透明度实现
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class transparency : MonoBehaviour
{
//时长
public float time=0.5f;
//定时器
public float timer;
//透明度 alpha值 0-1
float Alpha = 0.9f;
public float Alhpa { get; private set; }
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
Alhpa = (time - timer) / time;
gameObject.GetComponent<SpriteRenderer>().color = new Color(255, 255, 255, Alhpa);
}
}
|