เริ่มกันเลยครับ
1. ให้ทำการเตรียม Scene มา 2 Scene นะครับ เพื่อทำการโหลดระหว่าง Scene (ให้ทำการใส่ Models ด้วยนะครับ)
2. ทำการสร้างปุ่ม UI เพื่อทดสอบ Load Scene ครับ
3. จากนั้นทำการสร้าง C# Script (LoadSceneManager.cs) จากนั้นทำการเพิ่ม
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadSceneManager : MonoBehaviour
{
public void LoadScene(string sceneName)
{
StartCoroutine(LoadSceneObject(sceneName));
}
public IEnumerator LoadSceneObject(string sceneName)
{
AsyncOperation async = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
async.allowSceneActivation = false;
// Loop เพื่อตรวจสอบว่าโหลด Object เสร็จหรือยัง
while (!async.isDone)
{
// ทำการคำนวณ progress
float progress = Mathf.Clamp01(async.progress / 0.9f);
Debug.Log("Loading progress: " + (progress * 100).ToString("n0") + "%");
// Loading completed
if (progress == 1f)
{
async.allowSceneActivation = true;
}
yield return null;
}
}
}
เท่านี้ก็สามารถนำไปประยุกต์ ใช้งานต่อได้ละครับ
NO GAME NO DREAM !!!!