- Home /
Network.connections.Length is always 0
I have an empty gameObject with a script that contains below code snippet.
void FixedUpdate () {
if (isServer) {
Debug.Log ("NCL:" + Network.connections.Length);
}
}
Everytime a client connects, the above NCL value stays 0. What can be wrong here?
Hi,
Try calling your Debug.Log in this message:
void OnPlayerConnected () {
}
http://docs.unity3d.com/ScriptReference/Network.OnPlayerConnected.html
Hey Thanks ! But, I'm a little confused here. As per documentation, a host acts as a server as well as a client. So, I was wondering where to use these server related functions. I tried using it in the player script(this script is part of prefab that's spawned across the network using Network manager) but no luck. I tried adding [server], [command] before functions but that didn't worked either. I also tried creating an empty game object & then adding a script to it that contains server related functions but that was of no use as well. I know I'm not getting a thing which should be pretty obvious :(. All I wanted to know is where should I write the code to execute server commands. In other words, what is & where is my server after I spawn my players across the network.
Answer by seanr · Aug 10, 2015 at 08:15 PM
Network.connections is part of the old/legacy network API.
If you are using UNet, try NetworkServer.connections.
Thanks! And use NetworkServer.connections.Count
to get a number
Your answer
Follow this Question
Related Questions
UNET NetworkServer.Spawn intermittently not called on clients 1 Answer
Unity networking tutorial? 6 Answers
Local IP adress in UNet 4 Answers