Home > Blockchain >  Photon, How to get player variable
Photon, How to get player variable

Time:12-07

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.

CodePudding user response:

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.

  • Related