Hey, guys. These days i’m learning about unet. i have a script on player like this:
public class Test : NetworkBehaviour {
void Update () {
if (Input.GetMouseButtonDown (0) && isLocalPlayer)
Debug.Log (connectionToClient);
}
}
It works well if it’s host, but if it’s client the connectionToClient
is always null. I want use it to get the id in the network. Why it’s null ? and how to fix it? Thx.
As written in https://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity-connectionToClient.html
“The connection associated with this NetworkIdentity. This is only valid for player objects on the server.”
And by this, you can deduct that it’ll be always invalid in a client.
In the client, maybe you could use: https://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity-connectionToServer.html
But I’m not sure if it’ll work either.