Search Unity

Resolved Setting and Updating each player string custom properties using photon

Discussion in 'Multiplayer' started by shemtom2002ke, Nov 11, 2021.

  1. shemtom2002ke

    shemtom2002ke

    Joined:
    Jul 5, 2021
    Posts:
    19
    Hello, I am still new to using custom properties in Photon. I would love it see if someone would assist me!
    I am trying to allow each player to add/set their custom property which is a string. Unfortunately, I am still not able to update and get the word which each player saved, here is my code.

    Code (CSharp):
    1. public void GetWord()
    2.     {
    3.         StringWord = PlayerPrefs.GetString("secret", "no secret");
    4.     }
    5.     public void SetWord()
    6.     {
    7.         saveWord = InputSecret.text;
    8.         PlayerPrefs.SetWord("save", saveWord);
    9.      
    10.     }
    11. //added on click event of a button
    12. public void OnClickMyWord()
    13.     {
    14.         var hash = PhotonNetwork.LocalPlayer.CustomProperties;
    15.         hash.Add("Word", saveWord);
    16.         PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
    17.  
    18.         if (!PhotonNetwork.IsMasterClient) return;
    19.         SetWord();
    20.         Debug.Log(PhotonNetwork.LocalPlayer.ToStringFull());
    21.     }
    22. public override void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photon.Hashtable changedProps)
    23.     {
    24.         base.OnPlayerPropertiesUpdate(targetPlayer, changedProps);
    25.  
    26.         if (!PhotonNetwork.IsMasterClient) return;
    27.  
    28.         if (!changedProps.ContainsKey("Word")) return;
    29.  
    30.         Set
    31.     }
     
  2. shemtom2002ke

    shemtom2002ke

    Joined:
    Jul 5, 2021
    Posts:
    19

    1. Worked out fine. Finally got a solution!

      Code (CSharp):
      1.  
      2. //added on click event of a button
      3. public void OnClickMyWord()
      4.     {
      5.         saveWord = InputSecret.text;
      6.         var hash = PhotonNetwork.LocalPlayer.CustomProperties;
      7.         hash.Add("Word", saveWord);
      8.         PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
      9.         if (!PhotonNetwork.IsMasterClient) return;
      10.         Debug.Log(PhotonNetwork.LocalPlayer.ToStringFull());
      11.     }
      12. public override void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photon.Hashtable changedProps)
      13.     {
      14.         base.OnPlayerPropertiesUpdate(targetPlayer, changedProps);
      15.         if (!PhotonNetwork.IsMasterClient) return;
      16.         if (!changedProps.ContainsKey("Word")) return;
      17.         Set
      18.     }
     
unityunity