// Update is called once per frame void Update() { if (!isActiveAndEnabled) { return; } string text = "game has ended, here are the scores \n"; PlayerConnectionObject[] PCOs = FindObjectsOfType <PlayerConnectionObject>(); foreach (PlayerConnectionObject PCO in PCOs) { if (!PCO) { continue; } PlayerData pdata = PCO.GetComponent <PlayerData>(); text += pdata.playerName + " score: " + pdata.score + "\n"; } Text textRefernce = GetComponent <Text>(); if (textRefernce.text != text) { textRefernce.text = text; } }
// Update is called once per frame void Update() { if (!isActiveAndEnabled) { return; } string text = "game has ended, here are the scores \n"; PlayerConnectionObject[] PCOs = FindObjectsOfType <PlayerConnectionObject>(); float[] scores = new float[PCOs.Length]; int namesIndex = 0; foreach (PlayerConnectionObject PCO in PCOs) //find each player scores { if (!PCO) { Debug.Log("null PCO"); return; } PlayerData PD = PCO.GetComponent <PlayerData>(); if (!PD) { Debug.Log("null PD"); return; } float playerScore = PD.score; scores[namesIndex] = playerScore; namesIndex++; } doubleMergeSort(scores, PCOs); foreach (PlayerConnectionObject PCO in PCOs) { if (!PCO) { continue; } PlayerData pdata = PCO.GetComponent <PlayerData>(); text += pdata.playerName + " score: " + pdata.score + " kills: " + (pdata.killedEntityCount + pdata.killedPlayerCount) + " deaths: " + pdata.roundDeathCount + " jumps: " + pdata.roundJumpCount + "\n"; } Text textRefernce = GetComponent <Text>(); if (textRefernce.text != text) { textRefernce.text = text; } }
void updateRanks() { if (!isActive) //if script is disabled { CancelInvoke("updateRanks"); return; } PlayerConnectionObject[] PCOs = FindObjectsOfType <PlayerConnectionObject>(); int namesIndex = 0; string[] names = new string[PCOs.Length]; float[] scores = new float[PCOs.Length]; foreach (PlayerConnectionObject PCO in PCOs) //find each player scores { if (!PCO) { Debug.Log("null PCO"); return; } PlayerData PD = PCO.GetComponent <PlayerData>(); if (!PD) { Debug.Log("null PD"); return; } bool localPlayer = false; if (PCO.gameObject == gameObject)//this is the currentPlayer { localPlayer = true; } string playerName = PD.playerName; float playerScore = PD.score; names[namesIndex] = playerName; scores[namesIndex] = playerScore; namesIndex++; } doubleMergeSort(scores, names); displayScores(names, scores, namesIndex); }