- Home /
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++;
     }
 }
}
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                