- Home /
Getting a reference on a client when another client connects
So I'm developing a multiplayer game.
I need to get references to a Canvas attached to each player object for each player on the server so it can be rotated towards the the players individual local camera.
One way to doing this is by finding the reference in the Update method.
if (playerHealthBarCanvas == null
{
playerHealthBarCanvas = gameObject.GetComponentInChildren<Canvas>();
}
However I'd rather not do this.
What can I use, so that when a new player connects, every player already connected will get a reference to this object?
For the local player, I use:
public override void OnStartLocalPlayer()
{
playerHealthBarCanvas = gameObject.GetComponentInChildren<Canvas>();
}
This works for the local player quite fine and I'm wondering how I can do something similar for all the players on the network.
I have tried doing this in Start() but it doesn't work as I believe that start is run before the GameObject is actually instantiated on each client by the server.
I could obviously create a ClientRPC to get all the clients to do this but I'm sure there's a method I'm missing, because after all, the clients know when a new player connects because a new player is spawned into the game world!
Any help would be greatly appreciated.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Rpc Can't be called on client - Problem with client, works on server 1 Answer
Calling the Experts! Problems with Networking: Client/Server Architecture 1 Answer
Rigidbody that two players can move/interact with over network? 1 Answer
[UNET] Connection between Client and Server dies without message 0 Answers