一、新建一个js脚本命名为FadeInOut.js
加入如下代码:
//FadeInOut
//
//--------------------------------------------------------------------
//Public parameters
//--------------------------------------------------------------------
public varfadeOutTexture : Texture2D;
public varfadeSpeed =
0
.3;
vardrawDepth = -1000;
//--------------------------------------------------------------------
//Private variables
//--------------------------------------------------------------------
private varalpha =
1
.0;
private varfadeDir = -1;
//--------------------------------------------------------------------
//Runtime functions
//--------------------------------------------------------------------
//--------------------------------------------------------------------
functionOnGUI(){
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color.a = alpha;
GUI.depth = drawDepth;
GUI.DrawTexture(Rect( 0,
0,Screen.width, Screen.height), fadeOutTexture);
}
//--------------------------------------------------------------------
functionfadeIn(){
fadeDir = -1;
}
//--------------------------------------------------------------------
functionfadeOut(){
fadeDir = 1;
}
functionStart(){
alpha= 1;
fadeIn();
}
-------------------------------------------------------------------------------------------
把FadeInOut.js添加到你的摄像机下
二,然后自己做一个1x1像素,黑色背景的图像文件(例如PNG)
把该图像文件添加到FadeInOut中
三,想执行淡入淡出的时候只要执行
Camera.main.SendMessage("fadeOut");
或
Camera.main.SendMessage("fadeIn");
就可以了。
官方wiki(还包含C#版本):
[url]http://www.unifycommunity.com/wiki/index.php?title=FadeInOut