Search code examples
c#unity-game-enginephoton

Photon, How to get player variable


I'm putting Photon into my project but I would like to find out if a player is ready with customplayerproperties.

I've been able to set them using:

    Hashtable hash = new Hashtable();
    hash.Add("ready", false);
    PhotonNetwork.LocalPlayer.SetCustomProperties(hash);

But then I have no idea how to get that information back again from all players.

I have tried this method:

public override void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
{
    base.OnPlayerPropertiesUpdate(target, changedProps);
    
    if (!PhotonNetwork.IsMasterClient) 
        return;
    if (!changedProps.ContainsKey("ready"))
        return;
}

But when compiled into Unity I get the error:

The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)

And I get another error for that override being:

'PlayerReadied.OnPlayerPropertiesUpdate(Player, Hashtable)': no suitable method found to override

I don't know what to do here, if anyone could help that would be great!!

I really appreciate any help you can provide.


Solution

  • Check your 'using' statements in that file, it should have these I think:

    using Photon.Pun;
    using Photon.Realtime;
    

    Maybe related, if you are upgrading from Photon Unity Networking 1 to 2, there were namespace changes that might give you those issues: https://doc.photonengine.com/en-us/pun/current/getting-started/migration-notes

    Edit Do you have a 'Player' class in your program as well? I think your 'Player' class is being used in that method signature instead of PUN's one.