十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
项目中要用到加载场景的时候有个渐入渐出的效果,做了一下,跟大家分享

首先,创建两个场景Main和Game场景;
其次,在Main场景中创建FandeScene.cs脚本,创建Fade空对象,挂载,给一张黑色的图片,拖成预设体,同样也拖到Game场景中。
using UnityEngine;
using System.Collections;
public class FadeScene : MonoBehaviour {
public Texture blackTexture;
private float alpha = 1.0f;
public float fadespeed = 0.2f;
private int fadeDir = -1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
alpha += fadeDir * fadespeed * Time.deltaTime;
GUI.color = new Color (GUI.color .r ,GUI.color .g ,GUI.color .b,alpha);
GUI.DrawTexture (new Rect (0,0,Screen .width ,Screen .height), blackTexture);
}
public float BeginFade(int direction)
{
fadeDir = direction;
return 1 / fadespeed;
}
void OnLevelWasLoaded()
{
Debug.Log ("场景加载完毕!");
BeginFade (-1);
}
}再次,加载场景
协程加载
IEnumerator FadeLoadScene()
{
float time = GameObject.Find ("Fade").GetComponent ().BeginFade (1);
yield return new WaitForSeconds (time);
SceneManager.LoadSceneAsync ("Game");
} 这样运行,就会出现渐入渐出的效果。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。