- Home /
OnConnectedToServer not called when testing on same machine
I am trying to make a window appear once a client connects to a server, giving the option to select which team they would like to join.
I am using the following code to set a boolean once the client has connected to the server:
void OnConnectedToServer(){
justConnectedToServer = true;
}
And this code to define the window, and make it appear if the bool is true:
void JoinTeamWindow(int windowID){
if(GUILayout.Button ("Join Red Team", GUILayout.Height(buttonHeight))){
amIOnTheRedTeam = true;
justConnectedToServer = false;
}
if(GUILayout.Button ("Join Blue Team", GUILayout.Height(buttonHeight))){
amIOnTheBlueTeam = true;
justConnectedToServer = false;
}
}
void onGUI(){
if(justConnectedToServer == true){
joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;
joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;
joinTeamRect = new Rect (joinTeamLeftIndent, joinTeamTopIndent, joinTeamWindowWidth, joinTeamWindowHeight);
joinTeamRect = GUILayout.Window(0, joinTeamRect, JoinTeamWindow, joinTeamWindowTitle);
}
}
But, when I build the project, running a server in one instance and connecting to it in another, the window does not appear. Using the editor as the server, I can see that the client is connected.
I have run in background set to true, so the server is running while the client connects.
If you're on series 1 of GTGD, just download the script from the corresponding video on his website. www.gamertogamedeveloper.com/download
If you still need help, write in the comments and I'll do my best to help you, but his tutorials pretty much walk you through every single step.
Thanks, actually, my problem was that I was using "onGui" rather than "OnGui" so the Unity function wasn't called.
Your answer
Follow this Question
Related Questions
Very Confused on Networking HLAPI Practices 1 Answer
Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers
All players number in Network 1 Answer
"Trying to send command for object without authority" warning but the object is the localPlayer 1 Answer
Question regarding Server-Client approach in Unity 0 Answers