Hello,
I just started with Unity and C# and js. And i want to create a Multiplayer game wich is going really good only when a player connects to a server i goes thru photon servers wich is oke for internet and for the server browser to work. but the thing is that i also want player to be able to connect with IP and only over LAN without the signal ever going to the internet. I searched online but i could not find a solution. could you please help me? here is a part of my NetWorkmanager script.
//start een server
private void StartServer(){
Network.InitializeServer(4, 24000, !Network.HavePublicAddress());
//4 is hoeveel players en 25000 is de port
MasterServer.RegisterHost(typeName, gameName);
Debug.Log("Server Started");
}
void OnServerInitialized()
{
Debug.Log("Server Initializied");
SpawnPlayer();
canvas.SetActive(false);
}
//knop
void OnGUI()
{
if (!Network.isClient && !Network.isServer)
{
RefreshHostList();
//moet worden veranderd naar dat hij elke seconde checkt want dit kost heel veel frames
TextAway();
if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
StartServer();
//if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh"))
// RefreshHostList();
if (GUI.Button(new Rect(100, 250, 250, 100), "Quit"))
Application.Quit();
//joinIp("localhost:25000");
if (hostList != null)
{
for (int i = 0; i < hostList.Length; i++)
{
if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList*.gameName))*
_ JoinServer(hostList*);_
_ }_
_ }*_
* }*
* }*
* void TextAway(){*
* canvas.SetActive(true);*
* }*
* //check of er servers zijn*
* private HostData[] hostList;*
* private void RefreshHostList()*
* {*
* MasterServer.RequestHostList(typeName);*
* Debug.Log(“Refresh server list”);*
* }*
* void OnMasterServerEvent(MasterServerEvent msEvent)*
* {*
* if (msEvent == MasterServerEvent.HostListReceived)*
* hostList = MasterServer.PollHostList();*
* }*
* //join een server*
* private void JoinServer(HostData hostData)*
* {*
* Debug.Log(“connecting …”);*
* Network.Connect(hostData);*
* }*
* void OnConnectedToServer()*
* {*
* Debug.Log(“Server Joined”);*
* SpawnPlayer();*
* canvas.SetActive(false);*
* }*
* //join ip*
* void joinIp(string ip){*
* Debug.Log("connecting to " + ip);*
* Network.Connect(ip);*
* }*
* //spawn een player*
* public GameObject playerPrefab;*
* private void SpawnPlayer()*
* {*
* Network.Instantiate(playerPrefab, new Vector3(0f, 50f, 0f), Quaternion.identity, 0);*
* }*
}
I also tried connecting to IP but then i get an error that the server is not connected to photon main server. Iam dutch so all the comments are also in dutch i hope its not a problem :). i can change it if you want.