[Unity] 코드에서 씬(Scene) 전환하기
환경
- Unity
- C#
사용법
UnityEngine.SceneManagement
에 있는LoadScene
사용
using UnityEngine;
using UnityEngine.SceneManagement;
public class ExampleClass : MonoBehaviour
{
void Start()
{
SceneManager.LoadScene("OtherSceneName");
}
}
예시
- 충돌 발생시 scene 전환
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MoveCircle : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
SceneManager.LoadScene("GameOverScene");
}
}