Let’s say, on a client, I use a Command and in that Command I instantiate a sphere. In the same Command I also use NetworkServer.Spawn to spawn the sphere so that the sphere is managed by the network and all clients see it. After that, I want the client that spawned that sphere to have a reference to it so that the client can control it. This is where I’m stumped. I can’t figure out how to give the client this reference. It seems that I have to instantiate and spawn the sphere within the Command for it to spawn properly, and the Command only happens on the server. So once im at the server, I can’t refer to the client that called the Command… I hope you can help.
I have a game made with Photon Network, and when I need to instantiate something in network and get the reference I just use:
GameObject object = PhotonNetwork.Instantiate(object, position, Quaternion.identity, 0)
And for example, if the object I already instantiated has some behaviour that player can control, in the script of that behaviour attached to this object I check if that user is the owner.
void Update()
{
//Check if the object is mine, in other words, if I instantiate this object I can control
if (photonView.isMine)
CanControllTheObject();
}
If you use the Unity Network the concepts is the same.