using UnityEngine;
using System.Collections;
/// <summary>
/// Makes the multiplayer
/// </summary>
public class MultiplayerScript : MonoBehaviour {
//Variables Start _________________________
private string titleMessage = "GTGD Series 1 Prototype";
private string connectToIP = "127.0.0.1";
private int connectionPort = 26500;
private bool useNAT = false;
private string ipAddress;
private string port;
private int numberOfPlayers = 10;
public string playerName;
public string serverName;
public string serverNameForClient;
private bool iWantToSetupAServer;
private bool iWantToConnectToAServer;
//These cariables are used to define the main
//window.
private Rect connectionWindowRect;
private int connectionWindowWidth = 400;
private int connectionWindowHeight = 290;
private int buttonHeight = 60;
private int leftIndent;
private int topIndent;
//Variables End ________________________________
}
// Use this for initialization
void Start ()
{
serverName = PlayerPrefs.GetString ("serverName");
if(serverName == "")
{
serverName = "Server";
}
}
// Update is called once per frame
void Update () {
}
void ConnectWindow(int windowID)
{
//Leave a gap from the header.
GUILayout.Space(15);
//When the player launches the game they have the option
//to create a server or join a server. The variabels
//iWantToSetupAServer and iWantToConnectToAServer start as
//false so the player presencted with two buttons
//"Setup my server" and "Connect to a server".
if(iWantToSetupAServer == false iWantToConnectToAServer == false)
{
if(GUILayout.Button("Setup a server", GUILayout.Height (buttonHeight)))
{
iWantToSetupAServer = true;
}
GUILayout.Space(10);
if(GUILayout.Button("Connect to a server", GUILayout.Height(buttonHeight)))
{
iWantToConnectToAServer = true;
}
GUILayout.Space(10);
if(Application.isWebPlayer == false Application.isEditor == false)
{
if(GUILayout.Button("Exit Prototype", GUILayout.Height(buttonHeight)))
{
Application.Quit();
}
}
}
}
if(iWantToSetupAServer == true)
{
//The user can type a name for their server into
//the textfield.
GUILayout.Label("Enter a name for your server");
serverName = GUILayout.TextField(serverName);
GUILayout.Space(5);
//The user can type in the Port number for their server
//into textfield. We defined a default value above in the
//variabels as 26500.
GUILayout.Label("Server Port");
connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString ()));
GUILayout.Space(10);
if(GUILayout.Button("Start my own server", GUILayout.Height(30)))
{
//create the server
Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);
//save the servername using playerprefs.
PlayerPrefs.SetString("ServerName", serverName);
iWantToSetupAServer = false;
}
if(GUILayout.Button("Go Back", GUILayout.Height(30)))
{
iWantToSetupAServer = false;
}
}
void OnGUI()
{
//If the player disconnected then run the ConnectWindow function.
if(Network.peerType == NetworkPeerType.Disconnected)
{
//Determine the posistion of the window based on the width and
//height of the screen. The window will be placed in the middle
//of the screen
leftIndent = Screen.width / 2 - connectionWindowWidth / 2;
topIndent = Screen.height / 2 - connectionWindowHeight / 2;
connectionWindowRect = new Rect (leftIndent, topIndent, connectionWindowWidth,
connectionWindowHeight);
}
}
The screen shot shows that the compiler found an error on line 194. It’s possible it found errors before this, and you did not include the first error in the screenshot. Assuming line 194 is the first error, then locate that line and work out what’s wrong. Or, go over to Answers where there are many questions tagged with CS1519. From reading your code, I can’t see a problem on line 194, which makes me think there is an error earlier in the code. Line 168 looks odd.
As per your other thread, you have a block of random code (line 158 onwards) floating randomly outside of a function inside a class declaration and a bit of a mess with your bracket pairs at the bottom again. You also still have the random function name that I added for you to point out something-wasn’t-right-around-here.
I understand your learning to program (again, that’s great), but coming to the forums every 10mins when you get compiler errors from the absolute basics, isn’t going to teach you anything. Perhaps you need to find a good set of tutorials about the basics of programming
You actually had several brackets out of place which I fixed for you. All I did was fix your brackets and nothing else so I have no idea if it will work for you but it does compile now with no errors.
p.s I have no idea why it added all those extra returns.
using UnityEngine;
using System.Collections;
/// <summary>
/// Makes the multiplayer
/// </summary>
public class MultiplayerScript : MonoBehaviour {
//Variables Start _________________________
private string titleMessage = "GTGD Series 1 Prototype";
private string connectToIP = "127.0.0.1";
private int connectionPort = 26500;
private bool useNAT = false;
private string ipAddress;
private string port;
private int numberOfPlayers = 10;
public string playerName;
public string serverName;
public string serverNameForClient;
private bool iWantToSetupAServer;
private bool iWantToConnectToAServer;
//These cariables are used to define the main
//window.
private Rect connectionWindowRect;
private int connectionWindowWidth = 400;
private int connectionWindowHeight = 290;
private int buttonHeight = 60;
private int leftIndent;
private int topIndent;
//Variables End ________________________________
// }
// Use this for initialization
void Start ()
{
serverName = PlayerPrefs.GetString ("serverName");
if(serverName == "")
{
serverName = "Server";
}
}
// Update is called once per frame
void Update () {
}
void ConnectWindow(int windowID)
{
//Leave a gap from the header.
GUILayout.Space(15);
//When the player launches the game they have the option
//to create a server or join a server. The variabels
//iWantToSetupAServer and iWantToConnectToAServer start as
//false so the player presencted with two buttons
//"Setup my server" and "Connect to a server".
if(iWantToSetupAServer == false iWantToConnectToAServer == false)
{
if(GUILayout.Button("Setup a server", GUILayout.Height (buttonHeight)))
{
iWantToSetupAServer = true;
}
GUILayout.Space(10);
if(GUILayout.Button("Connect to a server", GUILayout.Height(buttonHeight)))
{
iWantToConnectToAServer = true;
}
GUILayout.Space(10);
if(Application.isWebPlayer == false Application.isEditor == false)
{
if(GUILayout.Button("Exit Prototype", GUILayout.Height(buttonHeight)))
{
Application.Quit();
}
}
}
// }
if(iWantToSetupAServer == true)
{
//The user can type a name for their server into
//the textfield.
GUILayout.Label("Enter a name for your server");
serverName = GUILayout.TextField(serverName);
GUILayout.Space(5);
//The user can type in the Port number for their server
//into textfield. We defined a default value above in the
//variabels as 26500.
GUILayout.Label("Server Port");
connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString ()));
GUILayout.Space(10);
if(GUILayout.Button("Start my own server", GUILayout.Height(30)))
{
//create the server
Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);
//save the servername using playerprefs.
PlayerPrefs.SetString("ServerName", serverName);
iWantToSetupAServer = false;
}
if(GUILayout.Button("Go Back", GUILayout.Height(30)))
{
iWantToSetupAServer = false;
}
}
}
void OnGUI()
{
//If the player disconnected then run the ConnectWindow function.
if(Network.peerType == NetworkPeerType.Disconnected)
{
//Determine the posistion of the window based on the width and
//height of the screen. The window will be placed in the middle
//of the screen
leftIndent = Screen.width / 2 - connectionWindowWidth / 2;
topIndent = Screen.height / 2 - connectionWindowHeight / 2;
connectionWindowRect = new Rect (leftIndent, topIndent, connectionWindowWidth,
connectionWindowHeight);
}
}
}
@drewradley props for helping the OP out. I do wonder if re-writing his code for him is the help he needs. (Give a man a fish and he can eat for a day. Teach a man to fish and he can feed for a lifetime.)