To start my code works and functions, but I am still new and wonder if my method might be a little sloppy or if it would cause performance issues in bigger games down the line. I am calling the code below for player respawn, from my method that checks to see if the game is over. What I am curious about is do I need to be using a break or something to stop the coroutine when it completes to make my code more performance compliant?
public void GameOver ()
{
playerLives -= 1;
livesText.text = "x " + playerLives;
if (playerLives > 0)
{
StartCoroutine(spawnPlayer());
}
if (playerLives <= 0)
{
gameOverText.text = "Game Over!";
gameOver = true;
audioSource.Play();
}
}
IEnumerator spawnPlayer()
{
yield return new WaitForSeconds(plySpawnWait);
Instantiate(player);
}