Hey everyone,
I’m VERY new to scripting and Unity and I’m working my way through some Brackey tutorials.
I’d like to music that plays when the game has ended. I have it setup so that the game currently ends when my box hits an object or falls off the world. This currently restarts the game and prints game ended to the console.
So the variable already exists that checks for a game end condition, but to be honest, I have no idea how to setup the reference for the sound.
I can think of the logic, I just don’t understand the code.
Basically, if EndGame = true, than play gameOverSound.
How do I code this?
My gameManager.cs looks like this:
public bool gameHasEnded = false;
public float restartDelay = 1f;
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("restart", restartDelay);
}
}
void restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
I created a new game object called soundManager to somehow check if the game has ended and play a sound.