Hello.I am having trouble with this script and here is the error:
Cannot implicitly convert type string' to int’
The script here:
using UnityEngine;
using System.Collections;
///
/// This script is attached to the MultiplayerManager and it
/// is the foundation for our multiplayer system.
///
public class MultiplayerScript : MonoBehaviour {
//Variable starts_________________________________
private string titleMessage = "Game Project";
private string connectToIP = "127.0.0.1";
private int connectionPort = "26500";
private bool useNAT = false;
private string ipAdress;
private string port;
private int numberOfPlayers = 10;
public string playerName;
public string serverName;
public string serverNameForClient;
private bool iWantToSetUpAServer = false;
private bool iWantToConnectToAServer = false;
//The variables is to define the main
//window.
private Rect connectionWindowRect;
private int connectionWindowWidth = 400;
private int connectionWindowHeight = 400;
private int buttonHeight = 60;
private int leftIndent;
private int topIndent;
//Variable 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 variables
//iWantToSetUpAServer and iWantToConnectToAServer start as
//false so the player is presented with two buttons
//"Setup my server" and "Connect to a server"
if(iWantToSetUpAServer == false && iWantToConnectToAServer == false)
{
if(GUILayout.Button("Set up 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 Game", GUILayout.Height(buttonHeight)))
{
Application.Quit();
}
}
}
if(iWantToSetUpAServer == true)
{
//The user can type a name for thier server into
//the textfield.
GUILayout.Label("Server Name");
serverName = GUILayout.TextField("serverName");
GUILayout.Space(5);
//The user can type in the Port number for thier server
//into the textfield.We defined a default value above in the
//variables as 26500.
GUILayout.Label("Server's Port");
connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString()));
GUILayout.Space(10);
if(GUILayout.Button("Start 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("Resume", GUILayout.Height(30)))
{
iWantToSetUpAServer = false;
}
}
void OnGUI()
{
//If the player is disconnected then run the ConnectWindow function.
if(Network.peerType == NetworkPeerType.Disconnected)
{
//Determine position of the window base 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);
connectionWindowRect = GUILayout.Window(0, connectionWindowRect, connectWindow,
titleMessage);
}
}
}
code number:
(18,44) private int connectionPort = “26500”;