Fix null reference
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user