Trying to finish of a game development project but having a couple issues that despite my last couple days of research I cannot figure out what the issue is.
Firstly being the error that occurs every time I die as it is meant to redirect you to a game over screen with your score which I save via PlayerPref
// THIS IS IN THE CharacterHealth.cs SCRIPT
void Die()
{
CurrentHealth = 0;
_characterXP.OnDeath();
SceneManager.LoadScene("NewGameOver");
}
// THIS IS IN THE CharacterXP.cs SCRIPT
public void OnDeath()
{
PlayerPrefs.SetInt("EndLevel", currentLevel);
}
But I keep getting the error: NullReferenceException: Object reference not set to an instance of an object before I can even get redirected to the Game Over screen.
Second issue being that I have two enemies that I placed onto the scene and the rest come from a script which spawns them every 5 to 10 seconds. The ones that are spawned from the script have the (Clone) in their name and I think that may be disrupting the script that works with the two pre-spawned monsters where killing them will give the player experience.
# IN THE EnemyHealth.cs SCRIPT
void Dead()
{
_characterXP.GainExp(40);
Destroy(gameObject);
}
# IN THE BossHealth.cs SCRIPT
void Dead()
{
_characterXP.GainExp(120);
Destroy(gameObject);
}
# IN THE CharacterXP.cs SCRIPT
public void GainExp(float expThatWasGained)
{
CurrentExp += expThatWasGained;
}
I have used the existing resources regarding these subjects but I still cannot find a solution, the reason why I asked a separate question.