溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Unity實現場景加載漸入漸出效果

發布時間:2020-04-03 03:59:23 來源:網絡 閱讀:832 作者:速度速度撒 欄目:開發技術

項目中要用到加載場景的時候有個漸入漸出的效果,做了一下,跟大家分享

首先,創建兩個場景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 <FadeScene> ().BeginFade (1);
        yield return new WaitForSeconds (time);
        SceneManager.LoadSceneAsync ("Game");
    }

這樣運行,就會出現漸入漸出的效果。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女