I'm trying to create a co-operative first person multiplayer game and I think I've misunderstood how Photon and RPC is supposed to work. I have a working first person multiplayer project where player avatars can see each other and move around as the player avatars have a photon view photon transform view. As part of the player controller script (handles player movement only for local player), which is attached to the player avatar prefab, I have an attribute:
public PlayerCharacterInfo myCharacter;
which contains all of the player's info and stats including name, level, currentHP, maxHP, etc which is added to the player avatar's PlayerController as it the player enters the room and their avatar is instantiated.
When I join a multiplayer room, each player can only see their own stats. For example, in the editor when running the game, only the values of the local editor player avatar are shown on the Player Controller myCharacter. I can see that the other player avatars have an instantiated myCharacter on them but no values are shown. At this point, I figure I just need to have an RPC function like this in my player controller that just reassigns the myCharacter to itself so it can be broadcasted to all:
[PunRPC]
void RPC_AddCharacter(PlayerCharacterInfo paramCharacter)
{
myCharacter = paramCharacter;
}
in void Start():
if(PV.IsMine)
{
PV.RPC("RPC_AddCharacter", RpcTarget.All, myCharacter);
}
But this does not let me see the myCharacter values for non-local player avatars.
My goal is to first show the name of the player avatar that you're looking at via a raycast, but I cannot even get this data to sync.
Have I got the right idea here, but I'm executing it wrong? Or is this just not how Photon works? Do I need to instead have each player's PlayerCharacterInfo stored in the room controller for each player or something like that?