原文地址:unity3d的图片淡入淡出代码
作者:amiliar
using UnityEngine;
using System.Collections;
public class SimpleFadeOut : MonoBehaviour {
public Texture2D blackScreen;
public float fadeOutTime = 2f;
float fadeOutTimer = 0f;
void Start () {
}
void Update () {
if (fadeOutTimer >= 0 && fadeOutTimer < fadeOutTime) {
fadeOutTimer += Time.deltaTime;
}
}
void OnGUI() {
if (fadeOutTimer < fadeOutTime) {
GUI.Window(-1,new Rect(0,0,Screen.width,Screen.height),OnBlScr,"",new GUIStyle());
GUI.BringWindowToFront(-1);
}
}
void OnBlScr(int index) {
GUI.color = new Color(1,1,1,1 - (fadeOutTimer / fadeOutTime));
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),blackScreen);
}
}