Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.36 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. static class ButtonHelper
  5. {
  6.  
  7.     public static Rect CreateBUttonRow (float x, float y, float fractionWidth, float fractionHeight)
  8.     {
  9.         float width = (((float)Screen.width) / fractionWidth);
  10.         float height = (((float)Screen.height) / fractionHeight);
  11.                
  12.         x *= width;// move x this many fractions
  13.         y *= height;// move y this many fractions
  14.                
  15.         return new Rect (x, y, width, height);
  16.        
  17.     }
  18.    
  19.    
  20. }
  21.  
  22. public class ButtonHelperBottom
  23. {
  24.     public static Rect CreateBUttonRow2 (float x, float fractionWidth, float fractionHeight)
  25.     {
  26.        
  27.         float width = (((float)Screen.width) / fractionWidth) ;
  28.        
  29.         float height = (((float)Screen.height) / fractionHeight);
  30.        
  31.         float y = Screen.Height - height;
  32.                 float x *= width;
  33.        
  34.         return new Rect (x, y, width, height);
  35.     }
  36. }
  37.  
  38.  
  39. public class WeaponsModeMenu : MonoBehaviour
  40. {
  41.     const float BorderX = 15.0f;
  42.         const float BorderY = 15.0f;
  43.  
  44.     bool AnotherButton (ref Rect rect, string text)
  45.     {
  46.         bool buttonValue = GUI.Button (rect, text);
  47.         rect.x += rect.width;
  48.         return buttonValue;
  49.     }
  50.     bool AnotherButtonBorder (ref Rect rect, string text)
  51.     {
  52.                 Rect borderedRect = rect;
  53.                 borderedRect.x += BorderX;
  54.                 borderedRect.width -= BorderX * 2;
  55.                 borderedRect.y += BorderY;
  56.                 borderedRect.height -= BorderY * 2;
  57.                 bool got = AnotherButton( ref borderedRect, text );
  58.                 borderedRect.x -= Borderx;
  59.                 borderedRect.width += BorderX * 2;
  60.                 borderedRect.y -= BorderY;
  61.                 borderedRect.height += BorderY * 2;
  62.                 rect = borderedRect;
  63.                 return got;
  64.                
  65.     }
  66.  
  67.     void OnGUI ()
  68.     {
  69.        
  70.         //top row reference rect
  71.         Rect topRowrect = ButtonHelper.CreateBUttonRow (0, 0);
  72.        
  73.         bool wasPressedC = AnotherButton (ref topRowrect, "Campaign");
  74.         if (wasPressedC) {
  75.             Application.LoadLevel ("Testmap Scene");
  76.         }
  77.        
  78.         bool wasPressedM = AnotherButton (ref topRowrect, "Multiplayer");
  79.         if (wasPressedM) {
  80.             Application.LoadLevel ("MultiPlayer Menu");
  81.         }
  82.        
  83.         bool wasPressedO = AnotherButton (ref topRowrect, "Options");
  84.         if (wasPressedO) {
  85.             Application.LoadLevel ("Options Menu");
  86.         }
  87.        
  88.         bool wasPressedQ = AnotherButton (ref topRowrect, "Quit");
  89.         if (wasPressedQ) {
  90.             Application.Quit ();
  91.         }
  92.        
  93.         bool wasPressedC1 = AnotherButton (ref topRowrect, "Campaign");
  94.         if (wasPressedC1) {
  95.             Application.LoadLevel ("Testmap Scene");
  96.         }
  97.        
  98.        
  99.         //bottom row reference rect
  100.         Rect bottomRowrect = ButtonHelperBottom.CreateBUttonRow2 (0);
  101.        
  102.         bool wasPressedx = AnotherButton (ref bottomRowrect, "Campaign");
  103.         if (wasPressedx) {
  104.             Application.LoadLevel ("Testmap Scene");
  105.         }
  106.        
  107.         bool wasPressedy = AnotherButton (ref bottomRowrect, "Campaign");
  108.         if (wasPressedy) {
  109.             Application.LoadLevel ("Testmap Scene");
  110.         }
  111.        
  112.         bool wasPressedz = AnotherButton (ref bottomRowrect, "Campaign");
  113.         if (wasPressedz) {
  114.             Application.LoadLevel ("Testmap Scene");
  115.         }
  116.        
  117.         bool wasPressed1 = AnotherButton (ref bottomRowrect, "Campaign");
  118.         if (wasPressed1) {
  119.             Application.LoadLevel ("Testmap Scene");
  120.         }
  121.        
  122.         bool wasPressed2 = AnotherButton (ref bottomRowrect, "Campaign");
  123.         if (wasPressed2) {
  124.             Application.LoadLevel ("Testmap Scene");
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement