Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

짱이 될거야

Unity Scene 전환 본문

프로젝트

Unity Scene 전환

jeong57 2022. 10. 31. 16:30

Unity에서 Scene 전환하기

 

1. File > New Scene: 새로운 scene 생성

New Scene 생성하기

2. Assets/Scenes에 저장

3. File > Build Settings... 클릭

File > Build Settings...

4. 생성한 Scene을 'Scenes In Build'에 넣는다. 그러면 인덱스가 생성되는데, 이 인덱스를 씬 전환에 사용한다. (이름으로 할 수도 있지만 그것보다는 인덱스가 좀 더 명확하다.)

File > Build Settings > 씬 삽입

5. Script에 씬 전환하는 코드를 작성해준다.

아래 예시 코드는 button을 누르면 count 숫자가 증가하고, count=2가 되면 scene이 0에서 1로 전환되도록 구현해두었다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;	// Scene 전환 위해서


public class ExampleScript : MonoBehaviour
{
    public Button submitBtn;

    public void Start()
    {
        submitBtn.onClick.AddListener(Input);
    }

    public void Input()
    {
        count++;
        if (count == 2)
        {
            SceneManager.LoadScene(1);
        }
    }

}

 

Comments