- Home /
Leader board Getting no error but not showing scores
Hi im making an quiz game and in the end of the game i saving the player name with the score. i dont have any idea how to make scoreboard so i follow this tutorial in youtube https://www.youtube.com/watch?v=U7p3wZsX7RY&t=1821s. i dont have an error but the score and name doesnt show when game run. I am modifying the string[] Scoreformat to save the value score from the gamecontroller scrip. Can anyone show an example line that can call and add into the list the score value inside the public void savescore and getscore. Thank you for future help.
     //saving scores in gamecontroller script
           public void Endround()
             {
                 isRoundActive = false;
                 dataCOntrollerT.SubmitNewplayerScore(playerScore);
                 endRoundScoretext.text = dataCOntrollerT.GetHIghestplayerScore().ToString();
         
         
                 FinalScore = playerScore;
                 PlayerPrefs.SetInt("FINAL_SCORE", FinalScore);
                 PlayerPrefs.Save();
         
         
                 questionDisplay.SetActive(false);
                 ROundendDisplay.SetActive(true);
             }
          
 
     //called in HighScoreManage Script
     
 public class playerScore
 {
     public string playerName;
     public int PlayerScore;
     public bool gotScore;
 
     public playerScore(string playerName, int playerScore)
     {
         this.playerName = playerName;
         this.PlayerScore = playerScore;
     }
 
     public string GetFormat()
     {
         return playerName + "~S~" + PlayerScore;
     }
 }
 
 public class HighScoreManager : MonoBehaviour
 {
     public int scoreCount = 5;
 
 
     [Header("SAVE PANEL")]
     public InputField inputName;
     public GameObject InputNameDisplay;
 
     [Header("SCORE DISPLAY")]
     public GameObject scoreObject;
     public GameObject scoreRoot;
     public Text textName, textScore;
     private playerScore playerscore;
     
     
   
     static HighScoreManager highScoreManager;
     static string separator = "~S~";
 
     int counter;
 
     void Start()
     {
         highScoreManager = this;
         
         SaveScoreNow();
     }
 
    void Update()
     {
         if (Input.GetKeyDown(KeyCode.S))
         {
 
             if (Input.GetKeyDown(KeyCode.P))
             {
                 List<playerScore> playerScores = GetScore();
                 foreach (playerScore p in playerScores)
                 {
                     print(p.playerName + "    " + p.PlayerScore);
                 }
             }
 
         }      
     }
 
     //save scores
     public void SaveScoreNow()
     {
         SaveScore(inputName.text, int.Parse(PlayerPrefs.GetInt("FINAL_SCORE").ToString()));
 
         List<playerScore> playerScores = GetScore();
 
         GetScore();
         counter++;
         if(counter % 1 == 1)
         {
             InputNameDisplay.gameObject.SetActive(false);
         }
       
     }
 
 
     IEnumerator CoShowScore()
     {
       
         while (scoreRoot.transform.childCount > 0) 
         {
             Destroy(scoreRoot.transform.GetChild(0).gameObject);
             yield return null;
         }
         List<playerScore> PlayerScore = GetScore();
 
         foreach (playerScore score in PlayerScore)
         {
             textName.text = score.playerName;
             textScore.text = score.PlayerScore.ToString();
 
 
             GameObject instantiadedScore = Instantiate(scoreObject);
             instantiadedScore.SetActive(true);
 
             instantiadedScore.transform.SetParent(scoreRoot.transform);
         }
     }
 
     
     //save score name and score
    public static void SaveScore(string name, int score)
     {
         List<playerScore> playerScores = new List<playerScore>();
         for (int i = 0; i < highScoreManager.scoreCount; i++)
         {
             if (PlayerPrefs.HasKey("FINAL_SCORE" + i))
             {
                 
                 string[] scoreFormat = PlayerPrefs.GetString("FINAL_SCORE" + i).Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                 playerScores.Add(new playerScore(scoreFormat[0], int.Parse(scoreFormat[1])));
             } else
             {
                 break;
             }
         }
 
         if (playerScores.Count < 1)
         {
             PlayerPrefs.SetString("Score0", name = separator = score.ToString());
             return;
         }
         playerScores.Add(new playerScore(name, score));
         playerScores = playerScores.OrderByDescending(o => o.PlayerScore).ToList();
 
         for (int i = 0; i <highScoreManager.scoreCount; i++)
         {
             if (i >= playerScores.Count) { break; }
             PlayerPrefs.SetString("FINAL_SCORE" + i, playerScores[i].GetFormat());
         }
     }
 
 
     //getting scores
     public List<playerScore> GetScore()
     {
         List<playerScore> playerScores = new List<playerScore>();
         for (int i = 0; i <highScoreManager.scoreCount; i++)
         {
             if (PlayerPrefs.HasKey("FINAL_SCORE" + i))
             {
                 
                 string[] scoreFormat = PlayerPrefs.GetString("FINAL_SCORE" + i).Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                 playerScores.Add(new playerScore(scoreFormat[0], int.Parse(scoreFormat[1])));
             } else
             {
                 break;
             }
         }
 
         return playerScores;
     }
 }  
Your answer
 
 
             Follow this Question
Related Questions
How to access and change scriptable objects on instantiated prefabs 1 Answer
how can i test to see if there are more than one objects with a tag C# 1 Answer
How to make a scoreboard? 0 Answers
How can I activate a GameObject Component of type script? 2 Answers
How to print a randomly selected string from Scriptable Objects? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                