Creating Success and Failed Scenes

Operating System

Creating the Success Scene

This scene will indicate if you successfully completed a level then you can proceed to the next level. First thing to do is to create a new Scene called Success. Then create a UI Image, just like what you did on the gameplay UI locate the sprite in the Sprites folder then attach it to Source Image. Rename it as Background and set its components values a shown below. tut38 Create now these several UI objects as follow (Text and 2 Buttons), and set each components as shown below.

Text

tut39 Buttons tut40tut41 After that create a panel and set its component same as the image below. tut42 Then add a UI Text as a child of the panel

Score

tut43

Child of the Score UI Text

tut44 Now that the UI Elements are ready we will now need to create Controllers to handle the event triggers. To do that create a new GameObject called it Next Level Controller. Then create a C# script save it inside the Game Controllers folder as NextLevelController. Import these important modules first:
  1. using UnityEngine.UI;
  2. using UnityEngine.SceneManagement;
Write these certain variables
  1. public Text scoreText;
  2. private int score;
After that write the rest of the code inside the class
  1. // Use this for initialization
  2. void Start () {
  3. InitializeVariables ();
  4. if (GameController.instance != null && MusicController.instance != null) {
  5. if(GameController.instance.isMusicOn){
  6. MusicController.instance.StopAllSound ();
  7. MusicController.instance.PlaySuccessSound ();
  8. }
  9. }
  10. }
  11.  
  12. void InitializeVariables(){
  13. score = GameController.instance.currentScore;
  14. scoreText.text = score.ToString ();
  15. }
  16.  
  17. public void NextButton(){
  18. SceneManager.LoadScene ("Gameplay");
  19. }
  20.  
  21. public void ExitButton(){
  22. SceneManager.LoadScene ("Main Menu");
  23. }
Attach the script to the GameObject inspector then drag and assign each corresponding component to script inspectors. tut45

Note: Make sure to attach the Script to each Buttons Runtime script.

Creating the Failed Scene

This scene will indicate if you failed a level then a prompt will indicate that can try again. First thing to do is to create a new Scene and save it as Failed. To make this easier just copy the Canvas UI and EventSystem, then paste it the Hierarchy of the Failed Scene. Just change Success Text to Fail Text then create a new GameObject called it Restart Controller. After that create a C# script called RestartController. Import these important modules first:
  1. using UnityEngine.UI;
  2. using UnityEngine.SceneManagement;
Write these certain variables
  1. public Text scoreText;
  2. private int score;
After that write the rest of the code inside the class
  1. // Use this for initialization
  2. void Start () {
  3. InitializeVariables ();
  4. if(GameController.instance != null && MusicController.instance != null){
  5. if(GameController.instance.isMusicOn){
  6. MusicController.instance.StopAllSound ();
  7. MusicController.instance.PlayFailedSound ();
  8. }
  9. }
  10. }
  11.  
  12. void InitializeVariables(){
  13. score = GameController.instance.currentScore;
  14. scoreText.text = score.ToString ();
  15. }
  16.  
  17. public void RestartButton(){
  18. SceneManager.LoadScene ("Gameplay");
  19. }
  20.  
  21. public void ExitButton(){
  22. SceneManager.LoadScene ("Main Menu");
  23. }
Attach the script to the GameObject inspector then drag and assign each corresponding component to script inspectors. tut46

Note: Make sure to attach the Script to each Buttons Runtime script.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Tags

Add new comment