Part 27 - Setting up the House: Make a game like Zelda using Unity and C#

01) 친구 집 내부 인테리어

Part 28 - Switching Scenes: Make a game like Zelda using Unity and C#

02) 씬 전환하기

Part 29 - Fading between Scenes: Make a game like Zelda using Unity and C#

03) 씬 전환 시 페이드 효과

[유니티 기초] 버튼 만들어 씬 전환 하기

04) Dialog to GameScene

[유니티(Unity)] 하나의 프로젝트 파일에서 다른 프로젝트 파일로 씬(Scene)을 이동하고 싶은 경우

05) 다른 프로젝트의 씬 가져오기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneTransition : MonoBehaviour
{
    public string sceneToLoad;
    public Vector2 playerPosition;
    public VectorValue playerStorage;
    public GameObject fadeInPanel;
    public GameObject fadeOutPanel;
    public float fadeWait;  // loading time

    private void Awake()
    {
        if (fadeInPanel != null)    // assigned
        {
            GameObject panel = Instantiate(fadeInPanel, Vector3.zero, Quaternion.identity) as GameObject;
            Destroy(panel, 1);
        }
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player") && !other.isTrigger)
        {
            playerStorage.initialValue = playerPosition;
            StartCoroutine(FadeCo());
            // SceneManager.LoadScene(sceneToLoad);
        }
    }

    public IEnumerator FadeCo()
    {
        if (fadeOutPanel != null)
        {
            Instantiate(fadeOutPanel, Vector3.zero, Quaternion.identity);
        }
        yield return new WaitForSeconds(fadeWait);  // 지정된 시간 후 재개
        AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneToLoad);
        while (!asyncOperation.isDone)
        {
            yield return null;  // after load the scene, it will be null
        }
    }
}