So I started looking to make my own Custom Network Manager and this is what I came up with:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using TMPro;
public class CustomNetworkManager : NetworkManager {
public void StartHosting()
{
SetPort();
NetworkManager.singleton.StartHost();
}
public void JoinGame()
{
SetIPAddress();
SetPort();
NetworkManager.singleton.StartClient();
}
private void SetIPAddress()
{
string ipAddress = GameObject.Find("InputFieldAddress").transform.Find("Text Area").transform.Find("Text").GetComponent<TMP_Text>().text;
NetworkManager.singleton.networkAddress = ipAddress;
}
void SetPort()
{
NetworkManager.singleton.networkPort = 7777;
}
private void OnLevelWasLoaded(int level)
{
if (level == 0)
SetupMainSceneButtons();
else
SetupOtherSceneButtons();
}
private void loadMainMenu()
{
GameObject menu1 = MyUtils.FindIncludingInactive("Multiplayer Menu");
GameObject menu2= MyUtils.FindIncludingInactive("Options Menu");
if (menu1.active)
menu1.SetActive(false);
else
menu2.SetActive(false);
GameObject menu = MyUtils.FindIncludingInactive("Main Menu");
menu.SetActive(true);
}
private void loadOptionsMenu()
{
GameObject menu = MyUtils.FindIncludingInactive("Main Menu");
menu.SetActive(false);
menu = MyUtils.FindIncludingInactive("Options Menu");
menu.SetActive(true);
}
private void loadMultiplayerMenu()
{
GameObject menu = MyUtils.FindIncludingInactive("Main Menu");
menu.SetActive(false);
menu = MyUtils.FindIncludingInactive("Multiplayer Menu");
menu.SetActive(true);
GameObject.Find("Host Game Button").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("Host Game Button").GetComponent<Button>().onClick.AddListener(StartHosting);
GameObject.Find("Join Game Button").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("Join Game Button").GetComponent<Button>().onClick.AddListener(JoinGame);
GameObject.Find("Back Button").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("Back Button").GetComponent<Button>().onClick.AddListener(loadMainMenu);
}
private void SetupMainSceneButtons()
{
GameObject menu = MyUtils.FindIncludingInactive("Main Menu");
menu.SetActive(true);
menu = MyUtils.FindIncludingInactive("Multiplayer Menu");
menu.SetActive(false);
menu = MyUtils.FindIncludingInactive("Options Menu");
menu.SetActive(false);
GameObject.Find("Multiplayer Button").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("Multiplayer Button").GetComponent<Button>().onClick.AddListener(loadMultiplayerMenu);
GameObject.Find("Options Button").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("Options Button").GetComponent<Button>().onClick.AddListener(loadOptionsMenu);
GameObject.Find("Quit Button").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("Quit Button").GetComponent<Button>().onClick.AddListener(loadMainMenu);
}
private void SetupOtherSceneButtons()
{
GameObject menu = MyUtils.FindIncludingInactive("NetworkButton");
menu.SetActive(true);
GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.AddListener(NetworkManager.singleton.StopHost);
}
}
Now, I went and tried to test my script and I found that I can’t connect 2 games via LAN (Which is the only option until now). I can LAN Host fine both on a standalone client or when pressing Play on Unity but I cannot for the life of me connect from either side.
I get DNS Resolution Failed: 11001 and UNet Client Error Connect Error: 11
All the other threads I have found have not helped me troubleshoot or solve this problem.