I am new to coding and I would like to know how to keep my object (coin) destroyed when the player collects it than dies and respawns which resets the scene and the coin comes back so the player can keep tallying his score up by dying.
here is my code for the coin
{
public AudioSource collectSound;
void OnTriggerEnter(Collider other)
{
collectSound.Play();
ScoringSystem.theScore += 10;
Destroy(gameObject);
}
and here is my code that makes the player respawn
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "obstacle")
{
movement.enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
}
here is my code for when the game restarts in my Gamemanager script
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("Game Over!");
Invoke("Restart", restartDelay);
}
}
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}