kmccmk9

Unity GUI Scale

Oct 17th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MainMenuGUI : MonoBehaviour {
  5.  
  6.     //Variables
  7.     public GUIStyle PlayButton;
  8.     public GUIStyle OptionsButton;
  9.     public GUIStyle InstructionsButton;
  10.     public GUIStyle ExitButton;
  11.     public Texture Background;
  12.     bool doWindow0 = false;
  13.    
  14.     // Use this for initialization
  15.     void Start () {
  16.    
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.         doWindow0 = false;
  22.     }
  23.    
  24.     void OnGUI () {
  25.         //GUI Matrix and GUI Scaling
  26.         Vector3 scale;
  27.         int originalWidth = 1600;
  28.         int originalHeight = 770;
  29.        
  30.         scale.x = Screen.width/originalWidth;
  31.         scale.y = Screen.height/originalHeight;
  32.         scale.z = 1;
  33.         Matrix4x4 svMat = GUI.matrix;
  34.         GUI.matrix = Matrix4x4.TRS(new Vector3(0,0,0), Quaternion.identity, scale);
  35.        
  36.         //Start Matrix
  37.         //Draw Background
  38.         GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),Background,ScaleMode.StretchToFill, false, 0.0f);
  39.         //End Draw Background
  40.        
  41.         //Draw PlayButton
  42.         if (GUI.Button(new Rect(30,180,235,590),"",PlayButton))
  43.         {
  44.             Application.LoadLevel("LoginScreen");
  45.         }
  46.         //End Draw PlayButton
  47.        
  48.         //Draw OptionsButton
  49.         GUI.Button(new Rect(260,330,220,440),"",OptionsButton);
  50.         //End Draw OptionsButton
  51.        
  52.         //Draw InstructionsButton
  53.         if (GUI.Button(new Rect(1160,330,145,440),"",InstructionsButton))
  54.         {
  55.             doWindow0 = true;
  56.         }
  57.         //End Draw InstructionsButton
  58.        
  59.         //Draw ExitButton
  60.         if (GUI.Button(new Rect(1320,180,265,590),"",ExitButton))
  61.         {
  62.             Application.Quit();
  63.         }
  64.         //End Draw ExitButton
  65.         //End Matrix
  66.         GUI.matrix = svMat;
  67.        
  68.         if (doWindow0 == true)
  69.             GUI.Window (0, new Rect(Screen.width/2-240,Screen.height/2-100,800,120), DoMyWindow, "Instructions:");
  70.     }
  71.    
  72.     void DoMyWindow (int windowID) {
  73.         GUI.Label (new Rect (10, 20, 800, 40), "Welcome to RedLightLife! Use WASD keys to move your character and use KL to rotate the camera. Use the J key to interact with people and objects. To have your character jump use the SPACEBAR. To pause your game, press the P key.");
  74.         if (GUI.Button (new Rect (10,80,100,20), "Close"))
  75.             doWindow0 = false;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment