Skip to content

Instantly share code, notes, and snippets.

@JonathanYin
Created July 17, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanYin/96e49f16d145cdb12bf135c1aca0b0d6 to your computer and use it in GitHub Desktop.
Save JonathanYin/96e49f16d145cdb12bf135c1aca0b0d6 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class GameOver : MonoBehaviour
{
int score = 0;
int score2 = 0;
public GUIElement gui;
public GUIElement gui2;
public GUIText myGUIText;
public GUIText myGUIText2;
private string scoreVariable;
private string scoreVariable2;
// Use this for initialization
void Start()
{
//get our score from playerprefs
score = PlayerPrefs.GetInt("Score");
//multiply by 10 as we did on displayed score
score = score * 10;
//it is not possible to add P1 and P2 tags to the text, since the GUIText itself uses info from the score
score2 = PlayerPrefs.GetInt("Score2");
score2 = score2 * 10;
}
void OnGUI()
{
myGUIText.text = scoreVariable;
myGUIText2.text = scoreVariable2;
//set our text to our score
scoreVariable = score.ToString();
scoreVariable2 = score2.ToString();
//if retry button is pressed load scene 0 the game
if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 155, 100, 40), "Retry?"))
{
SceneManager.LoadScene(1);
//Application.LoadLevel(0);
}
//and quit button
if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 205, 100, 40), "Quit"))
{
SceneManager.LoadScene(0);
//Application.Quit();
}
}
}
@JonathanYin
Copy link
Author

This script creates two GUI buttons to allow the player to retry (thus loading scene 1), or quit (going to scene 0, the loading screen). In addition, it displays the scores that the two players got.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment