From f3f911d99d8f430ab1ebbc038e51d244337b93c5 Mon Sep 17 00:00:00 2001 From: hungdk Date: Fri, 12 Sep 2025 00:53:17 +0700 Subject: [PATCH] Fix null reference --- Assets/Scripts/GameController.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index fc92235afb..6e7e36a102 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -20,12 +20,27 @@ public class GameController : MonoBehaviour if (instance == null) { instance = FindAnyObjectByType(); + if (instance == null) + { + var go = new GameObject("GameController"); + instance = go.AddComponent(); + DontDestroyOnLoad(go); + } } return instance; } } private void Awake() { + if(instance == null) + { + instance = this; + DontDestroyOnLoad(gameObject); + } + else if(instance != this) + { + Destroy(gameObject); + } } private void Start()