topical media & game development

talk show tell print

lib-unity-tutorial-m2h-2-Assets-Game-2-Jump-game-Scripts-GameGUI.cs / cs



  using UnityEngine;
  using System.Collections;
  
  public class GameGUI : MonoBehaviour {
  
      public static GameGUI SP;
      public static int score;
  
      private int bestScore = 0;
  
      void Awake()
      {
          SP = this;
          score = 0;
          bestScore = PlayerPrefs.GetInt("BestScorePlatforms", 0);
      }
  
      void OnGUI()
      {
          GUILayout.Space(3);
          GUILayout.Label(" Score: " + score);
          GUILayout.Label(" Highscore: " + bestScore);
  
          if (GameControl.gameState == GameState.gameover)
          {
              GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
  
              GUILayout.BeginHorizontal();
              GUILayout.FlexibleSpace();
              GUILayout.BeginVertical();
              GUILayout.FlexibleSpace();
  
              GUILayout.Label("Game over!");
              if (score > bestScore)
              {
                  GUI.color = Color.red;
                  GUILayout.Label("New highscore!");
                  GUI.color = Color.white;
              }
              if (GUILayout.Button("Try again"))
              {
                  Application.LoadLevel(Application.loadedLevel);
              }
  
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              GUILayout.FlexibleSpace();
              GUILayout.EndHorizontal();
              GUILayout.EndArea();
  
          }
      }
  
      public void CheckHighscore()
      {
          if (score > bestScore)
          {
              PlayerPrefs.SetInt("BestScorePlatforms", score);
          }
      }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.