I have an endless runner game and my player can respawn after wathing an ad. But after the player goes to the market page, or just tries again without reviving, unity gives the error
“MissingReferenceException: The object of type ‘Animator’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.”. I’m using LoadScene function to restart the game or coming back from the market.
This is my code for restarting the game after death.
public void TryAgain()
{
PlayerPrefs.SetInt("TotalMoney", numberOfCoins + PlayerPrefs.GetInt("TotalMoney"));
SceneManager.LoadScene(0);
scoreMultiplier = 1;
numberOfBullets = 0;
}
And this is the one that works after the ad ends. But error says it cant find the animator in here.
public void Revived()
{
moveSpeed = 10;
PlayerManager.scoreMultiplier = 1;
death = false;
animator.SetTrigger("Revive");
deathStuff.SetActive(false);
}