Here is my code for a singleton called Statistics :
public static Statistics instance;
public int numberOfEnnemyKilled=0;
private void Awake()
{
if (instance == null)
{
instance = this;
} else
{
Destroy(this);
}
}
public string GetTextEnnemyKilled()
{
return instance.numberOfEnnemyKilled.ToString();
}
When i call it like that in another script :
text.text = Statistics.instance.GetTextEnnemyKilled();
I get the error NullReferenceException: Object reference not set to an instance of an object, saying that this function return null. I dont know what I’m doing wrong. Thanks!