public void JoinGame() { if (ipInputField.text != "") { // validate the IP adress bool valid = ValidateIPv4(ipInputField.text); // if not valid, return. if (!valid) { outputLogsText.text = "The IP Adress is invalid."; return; } } // Add the Client Behaviour GameObject client = new GameObject(); clientBehaviour = client.AddComponent <ClientBehaviour>(); client.tag = "Client"; client.name = "Client"; gameObject.GetComponent <ClientGameManager>().enabled = true; gameObject.GetComponent <ClientGameManager>().SetOutputText(joinMessagesText, true); gameObject.GetComponent <ClientGameManager>().StartClientGameManager(); clientBehaviour.ClientStart(ipInputField.text); outputLogsText.text += "Joined the game."; // Update the UI lobbyUIGO.SetActive(true); joinUIGO.SetActive(true); gameObject.GetComponent <LobbyManager>().SetOutputText(joinMessagesText); joinOptionsGO.SetActive(true); }
/// <summary> /// Adds both a Serverbehaviour and a Clientbehaviour. /// </summary> public void HostGame() { if (ipInputField.text != "") { // validate the IP adress bool valid = ValidateIPv4(ipInputField.text); // if not valid, return. if (!valid) { outputLogsText.text = "The IP Adress is invalid."; return; } } // Add the Server Behaviour GameObject server = new GameObject(); server.AddComponent <ServerBehaviour>().ServerStart(ipInputField.text); server.name = "Server"; server.tag = "Server"; DontDestroyOnLoad(server); outputLogsText.text += "The room is created."; // Enable the HostGameManager gameObject.GetComponent <HostGameManager>().enabled = true; // Add the Client Behaviour GameObject client = new GameObject(); clientBehaviour = client.AddComponent <ClientBehaviour>(); client.name = "Client"; client.tag = "Client"; gameObject.GetComponent <ClientGameManager>().enabled = true; gameObject.GetComponent <ClientGameManager>().SetOutputText(hostMessagesText, true); gameObject.GetComponent <ClientGameManager>().StartClientGameManager(); clientBehaviour.ClientStart(ipInputField.text); // Update the UI to go to the Lobby lobbyUIGO.SetActive(true); hostUIGO.SetActive(true); gameObject.GetComponent <LobbyManager>().SetOutputText(hostMessagesText); hostOptionsGO.SetActive(true); }