- Home /
Unity Photon game scoreboard (player properties) any clear tutorials?
I have looked around and wand haven't found a clear tutorial how to build a scoreboard in photon. (Kills / deaths) using custom player properties in photon. I can add Kills / deaths to player properties, my problem is displaying the Scores in every player in my game, and display their Score / Name. this should be a very simple thing but theirs no tutorials on it...
Answer by ChristianSimon · Feb 13, 2017 at 01:18 PM
Hi,
I can add Kills / deaths to player properties
in this case you are already halfway through. Next step is to collect the data and bring it in a format your future scoreboard can work with. A simple solution might a list represented by a single string which contains player names, kills and deaths. For example:
string scores = string.Empty;
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
scores += p.NickName + " Kills:" + p.CustomProperties["kills"] + " Deaths" + p.CustomProperties["deaths"] + "\n";
}
You now have a simple list which can be displayed in the OnGUI() function, for example:
public void OnGUI()
{
GUILayout.Label(scores);
}
This a very simple solution, if you want to make it look more fancy and / or build the UI in the Editor and not from script, you need something similar to collect the player data and make it visible on the UI.
Thanks man! (Is their a way to get the highest score and tell that player they are the winner?) winner.setactive (if they have the highest score?)
There is no function implemented for this, so you need to do the sorting yourself. You can basically do the same as above, but this time you copy the necessary data (I guess it's UserId since it's unique and the score value) to a Dictionary for example and sort it by score afterwards.
To tell others that a client has won the game, you can use RPCs or RaiseEvent calls when adding scores for a local player. There are also other possible ways to achieve what you want, for example let the $$anonymous$$asterClient check the client scores regularly and let him decide to end the game, might be not the best solution. There is no predefined function for this behaviour either.
Hey, I have a similar thing and I'm trying to resolve it for a few weeks now, (noobHere)
I want to display on the UI the local client HP left and the enemy HP left but I can't figure out on how to access the other client's remaining HP... I know how to access it with OnGui as you mentioned above but I want something like:
HP (local): 300
Enemy (Other Client): 126.
I have another issue which I haven't begin to solve,
I want with a push of a button to view the other client camera without the UI and back again, is there a way?
Answer by Jesver · Nov 11, 2019 at 12:04 PM
@ChristianSimon hello I wanted to know how are we adding score to the player I did not find anything to sujuet on google
Your answer
Follow this Question
Related Questions
Score System Problem usying Photon 0 Answers
scoreboard for multiplayer game 0 Answers
For Loop Freezing Client (May be a Photon-related issue) 0 Answers
Photon Server Issue 0 Answers