using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WorldSaveManager : MonoBehaviour
{
ย ย public static WorldSaveManager instance;
ย ย [SerializeField] int worldSceneIndex = 1;
ย ย private void Awake()
ย ย {
ย ย ย ย if(instance == null)
ย ย ย ย {
ย ย ย ย ย ย instance = this;
ย ย ย ย }
ย ย ย ย else
ย ย ย ย {
ย ย ย ย ย ย Destroy(gameObject);
ย ย ย ย }
ย ย }
ย ย private void Start()
ย ย {
ย ย ย ย DontDestroyOnLoad(gameObject);
ย ย }
ย ย public IEnumerator LoadNewGame()
ย ย {
ย ย ย ย AsyncOperation LoadOperation = SceneManager.LoadSceneAsync(worldSceneIndex);
ย ย ย ย yield return null;
ย ย }
ย ย
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TitleScreenManager : MonoBehaviour
{
ย ย public void StartNewGame()
ย ย {
ย ย ย ย StartCoroutine(WorldSaveManager.instance.LoadNewGame());
ย ย }
ย ย
}
์น๋ด๋น๋ผย ์ต์ ํ ๊ฐ์๊ฑฐ ์ ๋ชฐ๋ผ์ ๋ณด๊ณ ์๊ฑธ๋ ค๋ ์ดํด ์ข ๋ถํํจ
๋ฐฐ์ด๊ฑฐ๋ก ์ด์ธํ ํ์ดํ ์ฌ ๋ณ๊ฒฝํด๋ณด๊ณ ์๋๋ฐย
NullReferenceException: Object reference not set to an instance of an object
TitleScreenManager.StartNewGame () (at Assets/TitleScreenManager.cs:9)
<<<์๊ฐ ์๊พธ ๋จ๋ฉด์ ์ฌ์ด ์๋ถ๋ฌ์์ง
๋ด ์คํฌ๋ฆฝํธ์ ๋ณ์๊ฐ ์ ์ธ ์๋๊ฑฐ๋ ์ปดํฌ๋ํธ๋ฅผ ์๋ถ๋ฌ์๊ฑฐ๋ ๊ทธ๋ฐ ๊ฑฐ ๋๋ฌธ์ด๋ผ๋๊ฑด ๊ตฌ๊ธ๋งํด์ ์์๋๋๋ฐ ์ ๋ชป์ฐพ๊ฒ ์...
๋์๋ค์ค
null์ด๋์
๋งค๋์ ํด๋์ค ์์ฑ์ํ๊ฑฐ์๋?
์๋๋ฉด startnewgameํจ์ ํธ์ถํ์ด๋ฐ์ ๋ด์ผ๋จ. ์ ๋งค๋์ awake์ ์ ํธ์ถ๋ผ์ ๊ทธ๋ฐ๊ฑฐ์ผ์๋ ์์
์๋๋๋ก ์์ฑ์์ ๋ฌธ์ ์ธ๋ฏ.