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 Arcticstar · Aug 04, 2017 at 11:08 AM · unity 5mysqlleaderboardhighscoresservice

Making Highscore table with mySql but name doesn't shows? Help please!

I created my server and did the php files and add scripts to the game it works fine but I get no name or score shows, only the ranking numbers like 1- 2- 3- 4-

here is the script

using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;

public class HSController : MonoBehaviour { private static HSController instance6;

 public static HSController Instance
 {
     get { return instance6; }
 }
 void Awake() {
     

DontDestroyOnLoad (gameObject); // If no Player ever existed, we are it. if (instance6 == null) instance6 = this; // If one already exist, it's because it came from another level. else if (instance6 != this) { Destroy (gameObject); return; }

 }
 void Start(){
     startGetScores ();
 startPostScores ();

     //
     //HSController.Instance.startGetScores ();
 }

 private string secretKey = "123456789"; // Edit this value and make sure it's the same as the one stored on the server
 string addScoreURL = "arcticstar.bplaced.net/addscore.php?"; //be sure to add a ? to your url
 string highscoreURL = "arcticstar.bplaced.net/display.php";

 //for testing
 public string uniqueID;
 public string name3;
 int score;


 public string[] onlineHighscore;

 public void startGetScores()
 {
     StartCoroutine(GetScores());
 }

 public void startPostScores()
 {    
     StartCoroutine(PostScores());
 }

 //set actual values before posting score
 public void updateOnlineHighscoreData()
 {
     // uniqueID,name3 and score will get the actual value before posting score
     uniqueID = "1234567890";// lace this TestScript variable into your game-variables
     name3 = "Testname";
     score = 1000;
 }

 public  string Md5Sum(string strToEncrypt)
 {
     System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
     byte[] bytes = ue.GetBytes(strToEncrypt);
     
     // encrypt bytes
     System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
     byte[] hashBytes = md5.ComputeHash(bytes);
     
     // Convert the encrypted bytes back to a string (base 16)
     string hashString = "";
     
     for (int i = 0; i < hashBytes.Length; i++)
     {
         hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
     }
     
     return hashString.PadLeft(32, '0');
 }
 
 // remember to use StartCoroutine when calling this function!
 IEnumerator PostScores()
 {
     updateOnlineHighscoreData ();
     //This connects to a server side php script that will add the name and score to a MySQL DB.
     // Supply it with a string representing the players name and the players score.
     string hash = Md5Sum(name3 + score + secretKey);
     //string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;
     string post_url = addScoreURL + "uniqueID=" + uniqueID+ "&name=" + WWW.EscapeURL (name3) + "&score=" + score+ "&hash=" + hash;
     //Debug.Log ("post url " + post_url);
     // Post the URL to the site and create a download object to get the result.
     WWW hs_post = new WWW("http://"+post_url);
     yield return hs_post; // Wait until the download is done
     
     if (hs_post.error != null)
     {
         print("There was an error posting the high score: " + hs_post.error);
     }
 }
 
 // Get the scores from the MySQL DB to display in a GUIText.
 // remember to use StartCoroutine when calling this function!
 IEnumerator GetScores()
 {


     Scrolllist.Instance.loading = true;

     WWW hs_get = new WWW("http://"+highscoreURL);

     yield return hs_get;
     
     if (hs_get.error != null)
     {
         //Debug.Log("There was an error getting the high score: " + hs_get.error);

     }
     else
     {

         //Change .text into string to use Substring and Split
         string help = hs_get.text;

         //help= help.Substring(5, hs_get.text.Length-5);
         //200 is maximum length of highscore - 100 Positions (name+score)

         onlineHighscore  = help.Split(";"[0]);

     }
     Scrolllist.Instance.loading = false;
     Scrolllist.Instance.getScrollEntrys ();
 }
 

}

and this is the scrollList.cs

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class Scrolllist : MonoBehaviour { // Use this for initialization

 private static Scrolllist instance5;
 
 public static Scrolllist Instance
 {
     get { return instance5; }
 }
 void Awake() {
     
     //DontDestroyOnLoad (gameObject);
     // If no Player ever existed, we are it.
     if (instance5 == null)
         instance5 = this;
     // If one already exist, it's because it came from another level.
     else if (instance5 != this) {
         Destroy (gameObject);
         return;
     }
 }

//

 public GameObject ScrollEntry;
 public GameObject ScrollContain;
 public int yourPosition;
 public GameObject LoadingText;
 public bool loading = true;

 void Update () {
 
     if (!loading)
         LoadingText.SetActive (false);
     else
         LoadingText.SetActive (true);
 }

 public void getScrollEntrys()
 {
     //Destroy Objects that exists, because of a possible Call bevore
     foreach (Transform childTransform in ScrollContain.transform) Destroy(childTransform.gameObject);

     int j = 1;
     for (int i=0; i<HSController.Instance.onlineHighscore.Length-1; i++) {
         GameObject ScorePanel;
         ScorePanel = Instantiate (ScrollEntry) as GameObject;
         ScorePanel.transform.parent = ScrollContain.transform;
         ScorePanel.transform.localScale = ScrollContain.transform.localScale;
         Transform ThisScoreName = ScorePanel.transform.Find ("ScoreText");
         Text ScoreName = ThisScoreName.GetComponent<Text> ();
         //
         Transform ThisScorePoints = ScorePanel.transform.Find ("ScorePoints");
         Text ScorePoints = ThisScorePoints.GetComponent<Text> ();
         //
         Transform ThisScorePosition = ScorePanel.transform.Find ("ScorePosition");
         Text ScorePosition = ThisScorePosition.GetComponent<Text> ();

         //first position is yellow
         if (j==1)
         {
             ScoreName.color=Color.yellow;
             ScorePoints.color=Color.yellow;
             ScorePosition.color=Color.yellow;
         }
         ScorePosition.text = j+". ";
         string helpString = "";

         helpString = helpString+HSController.Instance.onlineHighscore [i]+" ";
         i++;

         ScoreName.text = helpString;

         //
         ScorePoints.text = HSController.Instance.onlineHighscore [i];

         if(HSController.Instance.onlineHighscore [i]=="9999")
         {
             ScoreName.color=Color.red;
             ScorePoints.color=Color.red;
             ScorePosition.color=Color.red;
             yourPosition = j;
         }
         j++;

     }

 }

}

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

135 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 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 implement online leader board to my project? 0 Answers

Unity Game not correctly configured to use google play game services 0 Answers

Remember currently logged in player 1 Answer

MySql Android 1 Answer

Why it doesn't save data on the online database? 0 Answers


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