Fix null reference

This commit is contained in:
hungdk
2025-09-12 00:53:17 +07:00
parent 296edc369b
commit f3f911d99d
+15
View File
@@ -20,12 +20,27 @@ public class GameController : MonoBehaviour
if (instance == null)
{
instance = FindAnyObjectByType<GameController>();
if (instance == null)
{
var go = new GameObject("GameController");
instance = go.AddComponent<GameController>();
DontDestroyOnLoad(go);
}
}
return instance;
}
}
private void Awake()
{
if(instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else if(instance != this)
{
Destroy(gameObject);
}
}
private void Start()