Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by siaknimarkanthony · Jan 28, 2018 at 11:39 AM · scriptingbasicsscriptableobjectleaderboardscoreboard

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;
     }
 }  



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges