#How do i get a connections gameobject
1 messages · Page 1 of 1 (latest)
var connection = NetworkServer.connections[connectionId]
though if you want a safe way just in case then:
if(NetworkServer.connections.TryGetValue(connectionId, out var connection))
{
//Logic for connection
}
or
if(NetworkServer.connections.TryGetValue(connectionId, out var connection) == false) return;
//Then logic for connection
just part of the learning process
not something i'd rely on, but the connection Id does increment by one for each connection
ah might be wrong then, could depend on what transport you are using
ah, as the key in the dictionary is an int that isnt a good way to do it
foreach(var connection in NetworkServer.connections.Values)
{
sw.WriteLine(connection.identity.GetComponent<VoiceControl>().nickName);
}
thats the better way
or add .keys before the .count in yours
foreach can be easier to read though, so up to you
oh wait
sorry not .Keys
you want .Values, as the dictionary is Dictionary<key, value> and in this case its Dictionary<int, Connection>