Hi, I'm having a weird error in my code, it's "a namespace cannot contain certain members such as fields and methods"
playerName = GUILayout.TextField(playerName); connectToIp = GUILayout.Textfield(connectToIp); connectPort = Convert.ToInt32(GUI Layout.Textfield(connectport.ToString()));
}
else
{
(I've Used * to indicate where the errors are, They are above this line)
if(Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect Status: Connecting"); else if (Network.peerType == NetworkPeerType.Client) {
Can anyone help? Thanks for reading
EDIT: Here's the entire code.
*using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public string connectToIp = "127.0.0.1";
public int ConnectPort = 25000;
public bool useNAT = false;
public string ipaddress = ":";
public string port = "";
string playerName = "<Name ME>,";
void OnGUI()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
if (GUILayout.Button("Connect"))
{ if (playerName != "<Name ME>")
Network.useNat = useNAT;
Network.Connect(connectToIp, ConnectPort);
PlayerPrefs.SetString("playerName", playerName);
}
}
if (GUILayout.Button("Start Server"))
{
if (playerName != "<NAME ME>")
{
Network.useNat = useNAT;
Network.InitializeServer(32, ConnectPort);
foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
{
go.SendMessage("OnNetworkLoadedLevel",SendMessageOptions.DontRequireReceiver);
}
PlayerPrefs.SetString("playerName", playerName);
}
}
}
}
playerName = GUILayout.TextField(playerName); connectToIp = GUILayout.Textfield(connectToIp); connectPort = Convert.ToInt32(GUI Layout.Textfield(connectport.ToString()));
}
else
{
if(Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect Status: Connecting"); else if (Network.peerType == NetworkPeerType.Client) {
GUILayout.Label("Connection Status: Client!"); GUI Layout.Label("Ping to Server: " + Network.GetAveragePing(Network.connection(0]))); } else if (Network.peerType == NetworkPeerType.Server) { GUILayout.Label("Connection Status: Server!"); GUILayout.Lavel("Connections: " > Network.connection.Length); if (Network.connection.Length); GUILayout.Label("Ping to Server, " > Network.GetAveragePing(Network.connection[0]));
} if GUILayout.Button("Discount")) Network.Disconnect(200);
ipaddress = Network.player.ipaddress; port = Networkplayer.port.ToString(); //GUILayout.Label("IP Address: " > ipaddress + ":" port); }
} void OnConnectedToServer() { foreach (GameObject go in FindObjectsOfType(typeof(GameObject))
go.SendMessage("OnNetworkLoadedLevel", SendMessage.DontRequireReceiver);
}
}