How to properly use Player scores?
Options
Ziberian
✭
Hello everyone,
I am using the built-in player scores in my game, and they work very nicely for the most part. My only issue is, I want to reset points every time a player leaves the room (since I every run will start from fresh, everyone at 0).
When my game ends, you only have one option which is a button to leave the room, that button calls this coroutine:
IEnumerator LeavingRoom() { // Set score to zero while leaving Debug.Log("setting score 0"); PhotonNetwork.LocalPlayer.SetScore(0); PhotonNetwork.LocalPlayer.NickName = "Player Left"; ExitGames.Client.Photon.Hashtable properties = PhotonNetwork.LocalPlayer.CustomProperties; properties["readyToPlay"] = false; PhotonNetwork.LocalPlayer.SetCustomProperties(properties); PhotonNetwork.LeaveRoom(); while(PhotonNetwork.InRoom) yield return null; SceneManager.LoadScene("Lobby"); }
But sometimes this doesn't work? Like I even had this "test" script:
Debug.Log("Score: " + PhotonNetwork.LocalPlayer.GetScore()); PhotonNetwork.LocalPlayer.AddScore(2); Debug.Log("Score: " + PhotonNetwork.LocalPlayer.GetScore()); PhotonNetwork.LocalPlayer.SetScore(0); Debug.Log("Score: " + PhotonNetwork.LocalPlayer.GetScore());
and it prints out the same old score 3 times in a row (sometimes?). Do I need to do something where I need to "save" the score or something? Or wait a frame to pass?
Thanks in advanced!
0