so i have a multiplayer script (most of it is the GUI and everything) and all i want to do is to add a map chooser. when you are making a server, you get the option to choose map 1 or 2. (place holders) but i just don’t know how to tell the clients that are joining what the map is. do a make a prefab of the map and spawn it in when the map is chosen or do i change scenes. i don’t care how to do it, i just need some help pls?
here’s my whole multiplaer script if you need it.
using UnityEngine;
using System.Collections;
public class buttontest : MonoBehaviour {
public float leftPos = 0;
public float topPos = 0;
public float totalWidth = 100;
public float totalHeight = 50;
public Texture text;
private bool isWantingToPlayGame = false;
private bool isHostingServer = false;
private bool isJoiningServer = false;
public string serverName;
private int portNumber = 26500;
private int numberOfPlayers = 10;
private bool useNAT = false;
private Rect windowRect;
private Rect errorWindowRect;
public string playerName;
public string IPAddress;
private bool didFailToConnect = false;
private string conectionFailMessage;
private bool isContecting = false;
public int mapChooser = 0;
public string[] Maps = new string[] {"map 1", "map 2"};
// Use this for initialization
void Start () {
serverName = PlayerPrefs.GetString ("serverName");
if (serverName == "") {
serverName = "My Server";
}
IPAddress = PlayerPrefs.GetString ("IP");
if (IPAddress == "") {
IPAddress = "192.168.0.0";
}
}
// Update is called once per frame
void Update () {
}
void OnFailedToConnect (NetworkConnectionError error){
conectionFailMessage = error.ToString();
didFailToConnect = true;
}
void OnConnectedToServer (){
}
void errorWindow (int windowID){
GUILayout.Space (15);
GUILayout.Label ("could not connect:");
GUILayout.Space (5);
GUILayout.Label (conectionFailMessage);
GUILayout.Space (5);
if (GUILayout.Button ("Okay", GUILayout.Height (30))) {
didFailToConnect = false;
isContecting = false;
}
}
void JoinWindow (int windowID){
GUILayout.Space (15);
GUILayout.Label ("enter server's IP address");
IPAddress = GUILayout.TextField (IPAddress);
GUILayout.Space (5);
GUILayout.Label ("enter server's port number");
portNumber = int.Parse (GUILayout.TextField (portNumber.ToString ()));
GUILayout.Space (10);
if (GUILayout.Button ("connect", GUILayout.Height (30))) {
Network.Connect (IPAddress, portNumber);
PlayerPrefs.SetString ("IP", IPAddress);
isJoiningServer = false;
isContecting = true;
}
GUILayout.Space (5);
if (GUILayout.Button ("back", GUILayout.Height (30))) {
isJoiningServer = false;
}
}
void hostWindow (int windowID){
GUILayout.Space (15);
GUILayout.Label ("Enter server name");
serverName = GUILayout.TextField (serverName);
GUILayout.Label ("Enter the port number");
portNumber = int.Parse(GUILayout.TextField(portNumber.ToString()));
GUILayout.Space (5);
mapChooser = GUILayout.Toolbar (mapChooser, Maps);
GUILayout.Space (10);
if (GUILayout.Button ("start hosting", GUILayout.Height (30))) {
Network.InitializeServer (numberOfPlayers, portNumber, useNAT);
PlayerPrefs.SetString ("serverName", serverName);
isHostingServer = false;
}
GUILayout.Space (5);
if (GUILayout.Button ("back", GUILayout.Height (30))) {
isHostingServer = false;
}
}
void OnGUI(){
if (isWantingToPlayGame == false) {
GUI.DrawTexture (new Rect (520, 0, 300, 200), text);
if( GUI.Button (new Rect (520, 500, 300, 64), "let's play!")){
isWantingToPlayGame = true;
}
}
if (isWantingToPlayGame == true && isHostingServer == false && isJoiningServer == false && didFailToConnect == false && isContecting == false) {
if(Network.peerType == NetworkPeerType.Disconnected){
if(GUI.Button (new Rect (520, 37, 233, 64), "host a server")){
isHostingServer = true;
}
if(GUI.Button (new Rect (520, 120, 233, 64), "join a server")){
isJoiningServer = true;
}
if(Application.isWebPlayer == false && Application.isEditor == false){
if(GUI.Button (new Rect (520, 203, 233, 64), "exit game")){
Application.Quit();
}
}
}
}
if (isWantingToPlayGame == true && isHostingServer == true && isJoiningServer == false) {
if(Network.peerType == NetworkPeerType.Disconnected){
windowRect = new Rect(156, 12, 517, 294);
GUI.Window(0, windowRect, hostWindow, "host a server");
}
}
if (isWantingToPlayGame == true && isHostingServer == false && isJoiningServer == true) {
if(Network.peerType == NetworkPeerType.Disconnected){
windowRect = new Rect(156, 12, 517, 294);
GUI.Window(1, windowRect, JoinWindow, "join a server");
}
}
if (didFailToConnect == true) {
errorWindowRect = new Rect (156, 12, 150, 150);
GUI.Window(2, errorWindowRect, errorWindow, "ERROR");
}
}
}