I want to make a script for my networked player prefab that will spawn a gun in all networked instances of the scene. My gun script has a public variable that needs to contain a reference to the player controller that owns it.
How do you set a reference on an item you are spawning, so that no matter what networked instance of the scene the spawned item is running in, it’s reference variable will always point to the corresponding instance of the player controller and prefab that should own it in this instance of the scene?
Also, if anyone knows of some good diagrams about how all the different networking functions and commands work, I would love to see them.
Thanks for reading! (I hope you know the answer!)
First of all, here is a tutorial very well explain to make a Networking Game with Unet https://unity3d.com/learn/tutorials/topics/multiplayer-networking/introduction-simple-multiplayer-example?playlist=29690
It explain a lot of things about how networking is working.
To have diagrams, go on networking documentation of unity
Also, to bind your gun to your spawn player, go call on your player script, in the start :
If(isLocalPlayer){
Gameobject.Find("Path_To_Your_Gun).GetComponent<*Script_On_Your_Gun>().Variable_Containing_Reference_To_Your_Player = this.gameobject;
}
I have a couple extra quick networking questions. Is the host running 2 scenes on one computer, one for the server and one for the client, or is the host running one scene that is both the server and the client?
Also, with the network transform, what happens if an object is spawned on the server with a network transform component attached and the object is propagated to each client, if one client’s version of the object decides to move, will that transformation be propagated to all users, or will the server override it because it was spawned on the server and other clients should not be trying to move it?