- Home /
expecting (, found 'OnConnectedToServer'.
Hello, here is the part of the script that has the problem:
var ipAddress : String = "127.0.0.1";
var port : int = 25167;
var maxConnections : int = 10;
var PlayerGO : GameObject;
function OnGUI () {
if (Network.peerType == NetworkPeerType.Disconnected) {
GUILayout.BeginHorizontal ();
ipAdress = GUILayout.TextField (ipAddress);
GUILayout.Label ("IP ADDRESS");
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
var tempPort : String;
tempPort = GUILayout.TextField (port.ToString());
port = parseInt(tempPort);
GUILayout.Label ("PORT");
GUILayout.EndHorizontal ();
if (GUILayout.Button ("CONNECT")) {
for (var i : GameObject in GameObject.FindGameObjectsOfType (GameObject)) {
i.BroadcastMessage ("OnLoadNetworkLevel", SendMessageOptions.DontRequireReceiver);
}
print ("Connecting.... ");
Network.Connect (ipAddress, port);
}
if (GUILayout.Button ("START SERVER")) {
for (var i : GameObject in GameObject.FindGameObjectsOfType (GameObject)) {
i.BroadcastMessage ("OnLoadNetworkLevel", SendMessageOptions.DontRequireReceiver);
print ("Starting Server on " + ipAddress + ":" + port.ToString());
Network.InitializeServer (maxConnections, port);
}
}
else {
if (GUILayout.Button ("DISCONNECT")) {
Network.Disconnect (200);
}
}
}
function OnConnectedToServer () {
print ("Connected");
}
function OnLoadNetworkLevel () {
Network.Instantiate (playerGO, transform.position, transform.rotation, 0);
GetComponent (Camera).rect = Rect (0.7, 0.7, 0.25, 0.25);
GetComponent (GUILayer).enabled = false;
}
I keep getting: expecting (, found 'OnConnectedToServer'. every time I finish saving the script. What am I doing wrong?
We'll need to see the statement before this issue, to tell for sure. Expecting means that what it found is not a valid continuation of the last open statement.
Please put all of your code so we can see why it says that. We cant tell for sure right now
Judging by your previous questions like 'how to assign a main camera tag' and this where you refuse, to read what the error says, are you REALLY sure you want to make a networking game? Also you asked about the exact problem before, with an exact simiar 'expecting' error.
I am sorry. I shall look back at my answers and see if I can find a solution. if not, I will leave this question up.
Your answer
Follow this Question
Related Questions
Game Lags in Unity & after Build 4 Answers
Error... that I don't understand. 3 Answers
Unity Builden Game Crashes 0 Answers
Is it good to have many scripts? 1 Answer