Multiplayer Lobby in Lan

Hey, I’m new to Unity (1 year) and I want to make a LAN multiplayer game but I don’t know how to start. I’ve completed all the parts of the game (it’s a game played with 3 people, each having a unique role) and now I want to work on the connection part.

So, there are two buttons, one for Host and one for Join. I created the lobby scene with player selection that only the host can change (I don’t know how to do this) and I want to show all the game lobbies on the same network (LAN) so that the player can join. I also understand how Netcode-for-GameObjects works, but I don’t know how to use it for a local network game.

If anyone has any information to point me in the right direction, thank you very much.

1 Like

To make a multiplayer game running localy is quite simple. You just need to add a NetworkManager and UnityTransform components to your scene.

Added two buttons (Host and Join)

Then you can create a script to handle both connections:

using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

namespace Unrez
{
    public class ConnectionHandler : MonoBehaviour
    {
        [Header("References")]
        [SerializeField]
        private Button _buttonStartHost;
        [SerializeField]
        private Button _buttonStartClient;

        private void Start()
        {
            _buttonStartHost.onClick.AddListener(OnButtonStartHost);
            _buttonStartClient.onClick.AddListener(OnButtonStartClient);
        }

        private void OnDestroy()
        {
            _buttonStartHost.onClick.RemoveAllListeners();
            _buttonStartClient.onClick.RemoveAllListeners();
        }

        public void OnButtonStartHost()
        {
            Unbug.Log("OnButtonStartHost", Color.magenta);
            NetworkManager.Singleton.StartHost();
        }

        public void OnButtonStartClient()
        {
            Unbug.Log("OnButtonStartClient", Color.magenta);
            NetworkManager.Singleton.StartClient();
        }
    }
}

Don’t forget to add your prefab to the Player Prefab in the NetworkManager.

Just build and test in N computers in the same LAN.