Hello,
I have simple multiplayer script :
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
private const string typeName = "UniqueGameName";
private const string gameName = "RoomName";
private void StartServer()
{
Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
MasterServer.RegisterHost(typeName, gameName);
}
void OnServerInitialized()
{
Debug.Log("Server Initializied");
}
void OnGUI()
{
if (!Network.isClient !Network.isServer)
{
if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
StartServer();
if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
RefreshHostList();
if (hostList != null)
{
for (int i = 0; i < hostList.Length; i++)
{
if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
JoinServer(hostList[i]);
}
}
}
}
private HostData[] hostList;
private void RefreshHostList()
{
MasterServer.RequestHostList(typeName);
}
void OnMasterServerEvent(MasterServerEvent msEvent)
{
if (msEvent == MasterServerEvent.HostListReceived)
hostList = MasterServer.PollHostList();
}
private void JoinServer(HostData hostData)
{
Network.Connect(hostData);
}
void OnConnectedToServer()
{
Debug.Log("Server Joined");
}
}
Thing is I have a scene where I plan to create gui for server browser and server hosting but I dont know how to instantiate player in scene where is my main level when I select server. So if someone has somekind of pointers I would be grateful.