- Home /
How to make an online scoreboard
I have a multiplayer fish shoot game and i want that if you shooot a fish the other players see everbody's score go up i have now this script how can i make that if someone joins i see otherplayers score????
#pragma strict
function OnGUI ()
{
if(Network.isClient || Network.isServer)
{
for (var players = 1; players < Network.connections.Length + 2; players++)
{
GUI.Label(new Rect(100, 100 + (50 * (players-1)), 150, 30), "Player " + players + " score = " + Score.Punten);
}
}
}
i am dutch and 14 years old so i could have some spelling errors
Answer by ExtremePowers · Nov 11, 2014 at 07:18 PM
You would have to send the Score over the internet, you could make the server have a array with all the players scores in it.
@RPC
function SendScore(Score : int, Name : String) {
if (Network.isServer) {
p = new Player();
p.Score = Score;
p.Name = Name;
Players.Add(p);
}
}
var Players : List.<Player>[];
var score : int;
function Update() {
if (Network.isServer) {
Players = new List.<Player>[Network.connections.Length];
}
var name = PlayerPrefs.GetString("Username");
networkView.RPC("SendScore", RPCMode.All, score, name);
}
class Player {
var Score : int;
var Name : int;
}
@RPC
function RequestScoreboard(player : NetworkPlayer) {
if (Network.isServer) {
networkView.RPC("SendScoreboard", RPCMode.All, player, Players);
}
}
@RPC
function SendScoreboard(player : NetworkPlayer, SBoard : List.<Player>[]) {
if (Network.player == player) {
Players = SBoard;
}
}
//Call RequestScoreboard like this:
//networkView.RPC("RequestScoreboard", RPCMode.All, Network.player);
//Then draw the GUI here.
Thanks it is a very nice method I am surely going to use it is the best answer I imagined
regards Paul
But Extremepowers i have used your code and unity says:
The name 'List' does not denote a valid type ('not found'). Did you mean 'UnityEngine.Light'?
can you please help me again XD
thanks in advance
Your answer
Follow this Question
Related Questions
How can I keep a global score updatable from multiple GameObjects 1 Answer
How to create a HighScore using playerprefs based on passed time? 1 Answer
Saving game respectively my level, when I restart my game. 0 Answers
Saving travelled distance as a score 1 Answer
Scoreboard will not update 1 Answer