- Home /
Network object references to each other
Dear Unity Community,
I'm currently working on a project which is a basic peer-to-peer two player game. All I need to do is, create one player from prefab when the server got initialised, then if the other player got connected, create a player for him as well, and link them together in a script. What I can not figure out is, how can I rename the objects to have the same name on both client and server sides?
Any workaround solution would be greatly appreciated!
Answer by LBandy · Jun 27, 2012 at 12:10 PM
In case someone would need to do the same, I managed to figure this out. I added a single script to the prefab, which I used on Network.Instantiate.
void Start () {
networkView.RPC("PlayerNames", RPCMode.All, networkView.isMine, Network.isServer);
}
[RPC]
void PlayerNames (bool mine, bool serv) {
if (mine)
{
if (serv)
{
transform.name = "Player1";
}
else
{
transform.name = "Player2";
}
}
else
{
if (serv)
{
transform.name = "Player2";
}
else
{
transform.name = "Player1";
}
}
Your answer
Follow this Question
Related Questions
How can I spawn a GameObject on all players in my multiplayer game? 0 Answers
Network.Instantiate instantiazing 2 prefabs 1 Answer
All subsequent instantiated objects = auto-named with suffix (Clone)? 1 Answer
Multiplayer Projectile Instantiation 1 Answer
Network.Destroy doesn't remove objects on other systems? 2 Answers