Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MultiPlayerScript : MonoBehaviour {
  5.    
  6.     private string titleMessage = "Game Prototype";
  7.    
  8.     private string connectToIP = "127.0.0.1";
  9.    
  10.     private int connectionPort = "26500";
  11.    
  12.     private bool useNAT = false;
  13.    
  14.     private string ipAddress;
  15.    
  16.     private string port;
  17.    
  18.     private int numberOfPlayers = 10;
  19.    
  20.     public string playerName;
  21.    
  22.     public string serverName;
  23.    
  24.     public string serverNameForClient;
  25.    
  26.     private bool iWantToSetupAServer = false;
  27.    
  28.     private bool iWantToConnectToAServer = false;
  29.    
  30.     private Rect connectionWindowRect;
  31.    
  32.     private int connectionWindowWidth = 400;
  33.    
  34.     private int connectionWindowHeight = 280;
  35.    
  36.     private int buttonHeight = 60;
  37.    
  38.     private int leftIndent;
  39.    
  40.     private int topIndent;
  41.    
  42.  
  43.     void Start () {
  44.    
  45.     }
  46.    
  47.     void Update () {
  48.    
  49.     }
  50.    
  51.    
  52.     void ConnectWindow(int windowID)
  53.     {
  54.         GUILayout.Space(15);
  55.    
  56.    
  57.         if(iWantToSetupAServer == false && iWantToConnectToAServer == false)
  58.         {
  59.             if(GUILayout.Button("Setup a server", GUILayout.height(buttonHeight)))
  60.             {
  61.                 iWantToSetupAServer = true;
  62.             }  
  63.            
  64.             GUILayer.Space(10);
  65.            
  66.             if(GUILayout.Button("Connect to a server", GUILayout.Height(buttonHeight)))
  67.             {
  68.                 iWantToConnectToAServer = true;
  69.             }
  70.            
  71.             GUILayout.Space(10);
  72.            
  73.             if(Application.isWebPlayer == false && Application.isEditor == false)
  74.             {
  75.                 if(GUILayout.Button("Exit Prototype", GUILayout.Height(buttonHeight)))
  76.                 {
  77.                     Application.Quit();
  78.                 }
  79.             }
  80.         }  
  81.     }
  82.    
  83.    
  84.     void OnGUI()
  85.     {
  86.         if(Network.peerType == NetworkPeerType.Disconnected)
  87.         {
  88.            
  89.             leftIndent = Screen.width / 2 - connectionWindowWidth / 2;
  90.            
  91.             topIndent = Screen.height /2 - connectionWindowHeight / 2;
  92.            
  93.             connectionWindowRect = new Rect(leftIndent, topIndent, connectionWindowWidth,
  94.                                             connectionWindowHeight);
  95.            
  96.             connectionWindowRect = GUILayout.Window(0, connectionWindowRect, ConnectWindow,
  97.                                                     titleMessage);
  98.         }
  99.     }
  100.    
  101.    
  102.    
  103.    
  104.    
  105.    
  106.    
  107.    
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement