Question by
StuGuy · Sep 22, 2021 at 06:02 AM ·
networkingmultiplayerclient-servernew-feature
Using MLAPI, how do you get the client id. 2020.2
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
void OnGUI()
{
GUILayout.BeginArea(new Rect(10, 10, 300, 300));
var mode = NetworkManager.Singleton.IsHost ? "Host" : NetworkManager.Singleton.IsServer ? "Server" : "Client";
GUILayout.Label("Mode: " + mode);
GUILayout.Label("ulong: " + ulongId);
GUILayout.Label("ClientList: " + NetworkManager.Singleton.ConnectedClientsList.Count);
GUILayout.Label("Clients: " + NetworkManager.Singleton.ConnectedClients.Count);
GUILayout.Label("LocalClientId: " + Singleton.LocalClientId);
GUILayout.Label("ConnectedHostname: " + Singleton.ConnectedHostname);
GUILayout.Label("GetInstanceID: " + GetInstanceID());
GUILayout.Label("ConnectionData: " + Singleton.NetworkConfig.ConnectionData);
GUILayout.EndArea();
}
How do I get the incoming connection's id so I can make them client or host and spawn an object for them. The label's were my attempt at getting the Connection ID.
I've found these snippets
public event Action OnClientConnectedCallback (Doesn't work)
GetInstanceID - Gets object id not ulong connection
public void OnPlayerConnected (NetworkPlayer newPlayer) (Obsolete Old)
Comment
Your answer
Follow this Question
Related Questions
Multiplayer - Host can damage client, not vice versa? 1 Answer
Network.Connect is not working 1 Answer
Managed to set up Multiplayer Online on one Computer, but not on 2 0 Answers
ClientRPC not called from command on client instance during Start() 0 Answers
Unet: How can I know the percentage of packets lost? 1 Answer