daily pastebin goal
85%
SHARE
TWEET

Unity 3D State Manager: Level GUI C# Script

FIZIXAgency Aug 29th, 2012 2,429 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.         Unity 3D: Level GUI Script Source for State Manager
  3.        
  4.     Copyright 2012 FIZIX Digital Agency
  5.     http://www.fizixstudios.com
  6.        
  7.         For more information see the tutorial at:
  8.     http://www.fizixstudios.com/labs/do/view/id/unity-game-state-manager
  9.        
  10.        
  11.     Notes:
  12.         This script is a C# script provides a simple GUI that interfaces with the state manager, you
  13.         will need the statemanager.cs script and should review the gamestart.cs script for information
  14.         on how to implement the state manager.
  15. */
  16.  
  17.  
  18.  
  19. using UnityEngine;
  20. using System.Collections;
  21.  
  22. public class levelgui : MonoBehaviour {
  23.  
  24.         // Initialize level
  25.         void Start ()
  26.         {
  27.                 print ("Loaded: " + gamestate.Instance.getLevel());
  28.         }
  29.        
  30.        
  31.        
  32.         // ---------------------------------------------------------------------------------------------------
  33.         // OnGUI()
  34.         // ---------------------------------------------------------------------------------------------------
  35.         // Provides a GUI on level scenes
  36.         // ---------------------------------------------------------------------------------------------------
  37.         void OnGUI()
  38.         {              
  39.                 // Create buttons to move between level 1 and level 2
  40.                 if (GUI.Button (new Rect (30, 30, 150, 30), "Load Level 1"))
  41.                 {
  42.                         gamestate.Instance.setLevel("Level 1");
  43.                         Application.LoadLevel("level1");
  44.                 }
  45.                
  46.                 if (GUI.Button (new Rect (300, 30, 150, 30), "Load Level 2"))
  47.                 {
  48.                         print ("Moving to level 2");
  49.                         gamestate.Instance.setLevel("Level 2");
  50.                         Application.LoadLevel("level2");
  51.                 }
  52.                
  53.                
  54.                 // Output stats
  55.                 GUI.Label(new Rect(30, 100, 400, 30), "Name: " + gamestate.Instance.getName());
  56.                 GUI.Label(new Rect(30, 130, 400, 30), "HP: " + gamestate.Instance.getHP().ToString());
  57.                 GUI.Label(new Rect(30, 160, 400, 30), "MP: " + gamestate.Instance.getMP().ToString());
  58.                
  59.         }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top