Thursday, March 2, 2017

Day 18

Today I continued the tutorial.

I made a way where the game ends when you die and you can press 'R' to restart.

I made 2 more GUITexts, one called Restart Text, and the other Game Over Text. I set Restart text in the top right corner and the game over text a bit over the center middle.

Now I had to script them to actually do something. So I opened up the GameController script and wrote some stuff. I added 2 new GUIText variables(restartText, gameOverText) and 2 boolean variables(restart, gameOver) that I will use. I will use the booleans to pretty much check if the game is in a game over state or a restart state etc. I then made a public method called GameOver() and in it I wrote what to display in a game over state, I made the gameOverText.text = "Game Over" and made the variable gameOver = true.
Inside the DestroyByContact script under the if tag == player, I call the GameOver() method by doing gameController.GameOver();. And this worked. :D


Now I had to make a way to restart the game without having to exit and close it. So I'm gonna make it so that you can restart after the wave has cleared off the screen.

Inside the Game Controller script, under the while loop just after yield return new I wrote my code. I wrote and if statement that said if gameOver is true to make the restartText.text = "Press 'R' to Restart", made the variable restart = true and wrote break; so the it breaks the while loop so more waves don't spawn. 

This is how it looks:

Tomorrow I will be continuing the tutorial and hopefully build the game and upload it online.

No comments:

Post a Comment