32 lines
794 B
C#
32 lines
794 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;//注意添加RawImage命名空间
|
|
|
|
public class FadeInOutOpen : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public bool isBlack = false;//不透明状态
|
|
|
|
private float fadeSpeed = 5f;//透明度变化速率
|
|
public RawImage rawImage;
|
|
public RectTransform rectTransform;
|
|
|
|
|
|
void Start()
|
|
{
|
|
rawImage.color = Color.black;
|
|
rawImage.gameObject.SetActive(true);
|
|
rectTransform.sizeDelta = new Vector2(Screen.width, Screen.height);//使背景满屏
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
rawImage.color = Color.Lerp(rawImage.color, Color.clear, Time.deltaTime * fadeSpeed * 0.5f);//渐亮
|
|
|
|
if (rawImage.color.a < 0.05f)
|
|
{
|
|
rawImage.color = Color.clear;
|
|
rawImage.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
} |