I’ve got a little game I’m building, using the Photon Asteroid example as a model. that is, it has a ‘lobby’ where players gather, then enter the main scene.
When I load the main scene I instantiate player avatars. I must be doing something wrong, but it’s spooky what happens:
Player[] sorted = PhotonNetwork.PlayerList.OrderBy((p) => p.ActorNumber).ToArray();
Debug.Log(sorted.Length + " users in room");
foreach (Player p in sorted)
{
Debug.Log(string.Format("{0} {1}: is local {2}, is masterclient {3}, ", p.NickName, p.UserId, p.IsLocal, p.IsMasterClient));
if (p.IsLocal)
{
GameObject go = PhotonNetwork.Instantiate(playerPrefab.name, Camera.main.transform.position, Quaternion.identity, 0);
go.transform.parent = Camera.main.transform;
go.name = p.NickName;
go.SendMessage("SetAvatarName", p.NickName); ;
}
}
I’m assuming I’m only going to instantiate my avatar when it’s ‘local’ (that’s ‘me’ right?). In fact, I maybe don’t even need to see ‘me’ so I could avoid this?
Well here’s the spooky part. If I join one player from remote, I have 2 players when I enter this scene. One isLocal, the other is not. So, only ONE (the local one) should be created, yes? BUT TWO are created. And I cannot figure out where it’s coming from. This is the only place in the game I reference playerPrefab, and it’s in my class (unless it’s hiding a same-named object in a base class???) Anyway, the code that sets the name and avatar label does NOT get executed on the remote user. Everything else about the remote player works fine, I can see him moving properly about the scene.
Any insights welcome.
Edit: Or, is it that the PhotonNetwork.Instantiate creates this from the remote? But it doesn’t have the logic/data in place to set the name. And maybe that’s handled by PlayerCustomProperties??