您好,登錄后才能下訂單哦!
項目中要用到加載場景的時候有個漸入漸出的效果,做了一下,跟大家分享
首先,創(chuàng)建兩個場景Main和Game場景;
其次,在Main場景中創(chuàng)建FandeScene.cs腳本,創(chuàng)建Fade空對象,掛載,給一張黑色的圖片,拖成預(yù)設(shè)體,同樣也拖到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); } }
再次,加載場景
協(xié)程加載 IEnumerator FadeLoadScene() { float time = GameObject.Find ("Fade").GetComponent <FadeScene> ().BeginFade (1); yield return new WaitForSeconds (time); SceneManager.LoadSceneAsync ("Game"); }
這樣運行,就會出現(xiàn)漸入漸出的效果。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。