Hello, I have a problem that when I click on Servers and then on Start New Server in the GUI button overlap. I need to somehow do not overlap, but I do not know how.
Script 1 (Quit, Options, Multiplayer options script)
var voteyes = "F1";
var voteno = "F2";
var chat = "T";
var teamchat = "Y";
var nick = "Unkown";
var textvkonzoli = ";";
var konzole : boolean = false;
var options : boolean = false;
var multiplayeroptions : boolean = false;
var velikosti : boolean = false;
private var curVolume : float;
var style : GUIStyle;
function Qualities() {
switch (QualitySettings.currentLevel) {
case QualityLevel.Fastest:
GUILayout.Label("Fastest");
break;
case QualityLevel.Fast:
GUILayout.Label("Fast");
break;
case QualityLevel.Simple:
GUILayout.Label("Simple");
break;
case QualityLevel.Good:
GUILayout.Label("Good");
break;
case QualityLevel.Beautiful:
GUILayout.Label("Beautiful");
break;
case QualityLevel.Fantastic:
GUILayout.Label("Fantastic");
break;
}
}
function OnGUI(){
if(GUI.Button(Rect(800,210,70,25), "Servers", style)){
options = false;
velikosti = false;
multiplayeroptions = false;
GameObject.Find("Serverlist").SendMessage("ukazatservery");
}
if(GUI.Button(Rect(800,235,125,25), "Create new server", style)){
options = false;
velikosti = false;
multiplayeroptions = false;
GameObject.Find("Zalozeniserveru").SendMessage("ukazatzalozeni");
}
if(GUI.Button(Rect(800,260,125,25), "Multiplayer Options", style)){
options = false;
velikosti = false;
multiplayeroptions = true;
}
if(GUI.Button(Rect(800,285,80,25), "Options", style)){
options = true;
velikosti = false;
multiplayeroptions = false;
}
if(GUI.Button(Rect(800,310,70,25), "Quit", style)){
Application.Quit();
}
//***************************************************\\
if(options){
//VOLUME*******************************************************
curVolume = GUI.HorizontalSlider (Rect (500, 150, 100, 30), curVolume, 0.0, 1.0);
audio.volume = curVolume;
GUI.Label(Rect(250,145,50,50), "Volume");
//END OF VOLUME*************************************************
//GRAPHICS******************************************************
GUI.Label(Rect(250,170,50,50), "Graphic");
if(GUI.Button(Rect(500,170,70,20), "Lower")){
QualitySettings.DecreaseLevel();
}
if(GUI.Button(Rect(570,170,70,20), "Higher")){
QualitySettings.IncreaseLevel();
}
//END OF GRAPHICS***********************************************
//SCREEN RESOLUTION
GUI.Label(Rect(250,192,500,500), "Screen resolution");
if(GUI.Button(Rect(500,195,70,25), "640 x 480", style)){
velikosti = true;
}
if(velikosti){
if(GUI.Button(Rect(500,195,70,25), "640 x 480", style)){
Screen.SetResolution (640, 480, true, 60);
}
if(GUI.Button(Rect(500,220,70,25), "1024 x 768", style)){
Screen.SetResolution (1024, 768, true, 60);
}
if(GUI.Button(Rect(500,245,70,25), "1280 x 720", style)){
Screen.SetResolution (1280, 720, true, 60);
}
if(GUI.Button(Rect(500,270,70,25), "1280 x 768", style)){
Screen.SetResolution (1280, 768, true, 60);
}
if(GUI.Button(Rect(500,295,70,25), "1366 x 768", style)){
Screen.SetResolution (1366, 768, true, 60);
}
}
//END OF SCREEN RESOLUTION
}
//MULTIPLAYER OPTIONS*****************************************
if(multiplayeroptions){
GUI.Label(Rect(250,145,500,50), "Vote Yes:");
GUI.Label(Rect(250,165,500,50), "Vote No:");
GUI.Label(Rect(250,185,500,50), "Chat:");
GUI.Label(Rect(250,205,500,50), "Team Chat:");
GUI.Label(Rect(250,225,500,50), "Player Name:");
voteyes = GUI.TextField (Rect (350, 148, 25, 20), voteyes);
voteno = GUI.TextField (Rect (350, 168, 25, 20), voteno);
chat = GUI.TextField (Rect (350, 188, 25, 20), chat);
teamchat = GUI.TextField (Rect (350, 208, 25, 20), teamchat);
nick = GUI.TextField (Rect (350, 228, 100, 20), nick);
}
//END OF MULTIPLAYER OPTIONS*********************************
//KONZOLE********************************************************
if(konzole){
textvkonzoli = GUILayout.TextField (textvkonzoli, GUILayout.Width (Screen.width));
//UKAZAT FPS************************************
if (Input.GetKey(KeyCode.Return)) {
if (textvkonzoli == "/drawfps_1") {
//SCRIPT PRO ZOBRAZENÍ FPS
textvkonzoli = "";
} else {
//SCRIPT PRO SCHOVÁNÍ FPS
}
//SCHOVAT FPS*********************************
if (textvkonzoli == "/drawfps_0") {
//SCRIPT PRO SCHOVÁNÍ FPS
textvkonzoli = "";
} else {
//SCRIPT PRO ZOBRAZENÍ FPS
}
//QUIT*****************************************
if (textvkonzoli == "/quit") {
Application.Quit();
} else {
}
}
}
//END OF KONZOLE***********************************************
}
function Update(){
if (Input.GetKeyDown (KeyCode.Semicolon)){
if(konzole == false){
konzole = true;
Screen.showCursor = true;
}else{
konzole = false;
}
}
}
function Start(){
curVolume = audio.volume;
}
function DontDestroyOnLoad(){
audio.volume = curVolume;
}
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
Script2 (Start new server script)
DontDestroyOnLoad(this);
var ukazat : boolean = false;
var gameName = "You must change this";
var serverPort = 25002;
private var timeoutHostList = 0.0;
private var lastHostListRequest = -1000.0;
private var hostListRefreshTimeout = 10.0;
private var connectionTestResult : ConnectionTesterStatus = ConnectionTesterStatus.Undetermined;
private var filterNATHosts = false;
private var probingPublicIP = false;
private var doneTesting = false;
private var timer : float = 0.0;
private var useNat = false; // Should the server enabled NAT punchthrough feature
private var windowRect;
private var serverListRect;
private var hideTest = false;
// Enable this if not running a client on the server machine
//MasterServer.dedicatedServer = true;
function OnFailedToConnectToMasterServer(info: NetworkConnectionError)
{
Debug.Log(info);
}
function OnFailedToConnect(info: NetworkConnectionError)
{
Debug.Log(info);
}
function OnGUI ()
{
if(ukazat){
windowRect = GUILayout.Window (0, windowRect, MakeWindow, "Start new Server");
if (Network.peerType == NetworkPeerType.Disconnected MasterServer.PollHostList().Length != 0)
serverListRect = GUILayout.Window(1, serverListRect, MakeClientWindow, "Server List");
}
}
function Awake ()
{
windowRect = Rect(250,145,300,100);
serverListRect = Rect(0, 0, Screen.width - windowRect.width, 100);
// Start connection test
connectionTestResult = Network.TestConnection();
// What kind of IP does this machine have? TestConnection also indicates this in the
// test results
if (Network.HavePublicAddress())
Debug.Log("This machine has a public IP address");
else
Debug.Log("This machine has a private IP address");
}
function Update()
{
// If test is undetermined, keep running
if (!doneTesting)
TestConnection();
}
function TestConnection()
{
// Start/Poll the connection test, report the results in a label and react to the results accordingly
connectionTestResult = Network.TestConnection();
switch (connectionTestResult)
{
case ConnectionTesterStatus.Error:
doneTesting = true;
break;
case ConnectionTesterStatus.Undetermined:
doneTesting = false;
break;
case ConnectionTesterStatus.PublicIPIsConnectable:
useNat = false;
doneTesting = true;
break;
// This case is a bit special as we now need to check if we can
// circumvent the blocking by using NAT punchthrough
case ConnectionTesterStatus.PublicIPPortBlocked:
useNat = false;
// If no NAT punchthrough test has been performed on this public IP, force a test
if (!probingPublicIP)
{
Debug.Log("Testing if firewall can be circumvented");
connectionTestResult = Network.TestConnectionNAT();
probingPublicIP = true;
timer = Time.time + 10;
}
// NAT punchthrough test was performed but we still get blocked
else if (Time.time > timer)
{
probingPublicIP = false; // reset
useNat = true;
doneTesting = true;
}
break;
case ConnectionTesterStatus.PublicIPNoServerStarted:
break;
case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted:
Debug.Log("LimitedNATPunchthroughPortRestricted");
useNat = true;
doneTesting = true;
break;
case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric:
Debug.Log("LimitedNATPunchthroughSymmetric");
useNat = true;
doneTesting = true;
break;
case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone:
case ConnectionTesterStatus.NATpunchthroughFullCone:
Debug.Log("NATpunchthroughAddressRestrictedCone || NATpunchthroughFullCone");
useNat = true;
doneTesting = true;
break;
}
//Debug.Log(connectionTestResult + " " + probingPublicIP + " " + doneTesting);
}
function MakeWindow (id : int)
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
GUILayout.BeginHorizontal();
GUILayout.Space(10);
// Start a new server
if (GUILayout.Button ("Start Server"))
{
Network.InitializeServer(32, serverPort, useNat);
MasterServer.RegisterHost(gameName, "stuff", "l33t game for all");
}
// Refresh hosts
if (GUILayout.Button ("Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout)
{
MasterServer.RequestHostList (gameName);
lastHostListRequest = Time.realtimeSinceStartup;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
else
{
if (GUILayout.Button ("Disconnect"))
{
Network.Disconnect();
MasterServer.UnregisterHost();
}
GUILayout.FlexibleSpace();
}
}
function MakeClientWindow(id : int)
{
GUILayout.Space(5);
var data : HostData[] = MasterServer.PollHostList();
var count = 0;
for (var element in data)
{
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !(filterNATHosts element.useNat) )
{
var connections = element.connectedPlayers + "/" + element.playerLimit;
GUILayout.Label(element.gameName);
GUILayout.Space(5);
GUILayout.Label(connections);
GUILayout.Space(5);
var hostInfo = "";
// Indicate if NAT punchthrough will be performed, omit showing GUID
if (element.useNat)
{
GUILayout.Label("NAT");
GUILayout.Space(5);
}
// Here we display all IP addresses, there can be multiple in cases where
// internal LAN connections are being attempted. In the GUI we could just display
// the first one in order not confuse the end user, but internally Unity will
// do a connection check on all IP addresses in the element.ip list, and connect to the
// first valid one.
for (var host in element.ip)
hostInfo = hostInfo + host + ":" + element.port + " ";
//GUILayout.Label("[" + element.ip + ":" + element.port + "]");
GUILayout.Label(hostInfo);
GUILayout.Space(5);
GUILayout.Label(element.comment);
GUILayout.Space(5);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Connect"))
Network.Connect(element);
}
GUILayout.EndHorizontal();
}
}
function ukazatzalozeni(){
ukazat = true;
}
Script3 (Servers script)
var ukazat : boolean = false;
var gameName = "You must change this";
var serverPort = 25002;
private var timeoutHostList = 0.0;
private var lastHostListRequest = -1000.0;
private var hostListRefreshTimeout = 10.0;
private var connectionTestResult : ConnectionTesterStatus = ConnectionTesterStatus.Undetermined;
private var filterNATHosts = false;
private var probingPublicIP = false;
private var doneTesting = false;
private var timer : float = 0.0;
private var useNat = false; // Should the server enabled NAT punchthrough feature
private var windowRect;
private var serverListRect;
private var hideTest = false;
// Enable this if not running a client on the server machine
//MasterServer.dedicatedServer = true;
function OnFailedToConnectToMasterServer(info: NetworkConnectionError)
{
Debug.Log(info);
}
function OnFailedToConnect(info: NetworkConnectionError)
{
Debug.Log(info);
}
function OnGUI ()
{
if(ukazat){
windowRect = GUILayout.Window (0, windowRect, MakeWindow, "Server list");
if (Network.peerType == NetworkPeerType.Disconnected MasterServer.PollHostList().Length != 0)
serverListRect = GUILayout.Window(1, serverListRect, MakeClientWindow, "Server List");
}
}
function Awake ()
{
windowRect = Rect(250,145,300,100);
serverListRect = Rect(0, 0, Screen.width - windowRect.width, 100);
// Start connection test
connectionTestResult = Network.TestConnection();
// What kind of IP does this machine have? TestConnection also indicates this in the
// test results
if (Network.HavePublicAddress())
Debug.Log("This machine has a public IP address");
else
Debug.Log("This machine has a private IP address");
}
function Update()
{
// If test is undetermined, keep running
if (!doneTesting)
TestConnection();
}
function TestConnection()
{
// Start/Poll the connection test, report the results in a label and react to the results accordingly
connectionTestResult = Network.TestConnection();
switch (connectionTestResult)
{
case ConnectionTesterStatus.Error:
doneTesting = true;
break;
case ConnectionTesterStatus.Undetermined:
doneTesting = false;
break;
case ConnectionTesterStatus.PublicIPIsConnectable:
useNat = false;
doneTesting = true;
break;
// This case is a bit special as we now need to check if we can
// circumvent the blocking by using NAT punchthrough
case ConnectionTesterStatus.PublicIPPortBlocked:
useNat = false;
// If no NAT punchthrough test has been performed on this public IP, force a test
if (!probingPublicIP)
{
Debug.Log("Testing if firewall can be circumvented");
connectionTestResult = Network.TestConnectionNAT();
probingPublicIP = true;
timer = Time.time + 10;
}
// NAT punchthrough test was performed but we still get blocked
else if (Time.time > timer)
{
probingPublicIP = false; // reset
useNat = true;
doneTesting = true;
}
break;
case ConnectionTesterStatus.PublicIPNoServerStarted:
break;
case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted:
Debug.Log("LimitedNATPunchthroughPortRestricted");
useNat = true;
doneTesting = true;
break;
case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric:
Debug.Log("LimitedNATPunchthroughSymmetric");
useNat = true;
doneTesting = true;
break;
case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone:
case ConnectionTesterStatus.NATpunchthroughFullCone:
Debug.Log("NATpunchthroughAddressRestrictedCone || NATpunchthroughFullCone");
useNat = true;
doneTesting = true;
break;
}
//Debug.Log(connectionTestResult + " " + probingPublicIP + " " + doneTesting);
}
function MakeWindow (id : int)
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
GUILayout.BeginHorizontal();
GUILayout.Space(10);
// Refresh hosts
if (GUILayout.Button ("Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout)
{
MasterServer.RequestHostList (gameName);
lastHostListRequest = Time.realtimeSinceStartup;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
function MakeClientWindow(id : int)
{
GUILayout.Space(5);
var data : HostData[] = MasterServer.PollHostList();
var count = 0;
for (var element in data)
{
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !(filterNATHosts element.useNat) )
{
var connections = element.connectedPlayers + "/" + element.playerLimit;
GUILayout.Label(element.gameName);
GUILayout.Space(5);
GUILayout.Label(connections);
GUILayout.Space(5);
var hostInfo = "";
// Indicate if NAT punchthrough will be performed, omit showing GUID
if (element.useNat)
{
GUILayout.Label("NAT");
GUILayout.Space(5);
}
// Here we display all IP addresses, there can be multiple in cases where
// internal LAN connections are being attempted. In the GUI we could just display
// the first one in order not confuse the end user, but internally Unity will
// do a connection check on all IP addresses in the element.ip list, and connect to the
// first valid one.
for (var host in element.ip)
hostInfo = hostInfo + host + ":" + element.port + " ";
//GUILayout.Label("[" + element.ip + ":" + element.port + "]");
GUILayout.Label(hostInfo);
GUILayout.Space(5);
GUILayout.Label(element.comment);
GUILayout.Space(5);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Connect"))
Network.Connect(element);
}
GUILayout.EndHorizontal();
}
}
function ukazatservery(){
ukazat = true;
}
Thanks, advanced.