If anyone can help with this, it would be greatly appreciated. I have an online high score board working for my game. But, it would be nice to have the names align left in the window, and the scores align right, to give it that “Arcade” look. I send the Player’s name and score to the MySQL server and then retrieve the list of scores. But to get the alignments, I’m thinking I need to parse the names and scores after retrieving them. Any ideas on how to do this in C#?
Here is a screen shot:
Here is what the code looks like:
using UnityEngine;
using System.Collections;
using System.Text;
using System.Security;
public class Highscore : MonoBehaviour{
//DECLARE VARIABLES - WEB CONNECTIONS
public string secretKey = "aliensyncscores";
public string PostScoreUrl = "http://www.aliensync.com/games/highscore/postScore.php?";
public string GetHighscoreUrl = "http://www.aliensync.com/games/highscore/getHighscore.php";
private string name = "Name";
private int score;
private string WindowTitel = "";
private string Score = "";
public int dataSendCount;
public Rect demoArea;
public string postdata;
public int scoredata;
public string namedata;
public GUISkin Skin;
public float windowWidth = 380;
private float windowHeight = 300;
public Rect windowRect;
public int maxNameLength = 15;
public int getLimitScore = 10;
public Transform gameCon;
private GameControl gamecon;
//INITIALIZE SOME VARIABLES-------------------->
void Start (){
gamecon=gameCon.GetComponent<GameControl>();
dataSendCount=0;
score=gamecon.gamePoints;
}
//SETUP FOR CONDITIONS TO POST DATA TO PHP
void Update (){
if(gamecon.hiScoreSection==1){
if(dataSendCount<3){
dataSendCount+=1;
}
}
if(dataSendCount==1){
StartCoroutine(PostScore());
}
windowRect = new Rect (Screen.width*0.5f -(windowWidth*0.5f), 10, windowWidth, Screen.height*0.75f);
windowHeight = Screen.height*0.75f;
}
//BRING THE NAME AND SCORE DATA FROM PHP-------------------->
IEnumerator GetScore(){
Score = "";
WindowTitel = "Loading";
WWWForm form = new WWWForm();
form.AddField("limit",getLimitScore);
WWW www = new WWW(GetHighscoreUrl,form);
yield return www;
if(www.text == ""){
print("There was an error getting the high score: " + www.error);
WindowTitel = "There was an error getting the high score";
}else{
WindowTitel = "HISCORES";
Score = www.text;
}
}
//SEND THE NAME AND SCORE DATA TO PHP-------------------->
IEnumerator PostScore(){
string _name = name;
int _score = score;
string hash = Md5Sum(_name + _score + secretKey).ToLower();
WWWForm form = new WWWForm();
form.AddField("name",_name);
form.AddField("score",_score);
form.AddField("hash",hash);
WWW www = new WWW(PostScoreUrl,form);
WindowTitel = "Wait";
yield return www;
if(www.text == "done"){
StartCoroutine("GetScore");
}else {
print("There was an error posting the high score: " + www.error);
WindowTitel = "There was an error posting the high score";
}
}
//CAPTURE DATA
void OnGUI(){
GUI.skin = Skin;
//CONDITION 0: CAPTURE FROM PLAYER NAME AND SCORE TO SEND TO PHP-------------------->
if(gamecon.hiScoreSection==0){
demoArea= new Rect(Screen.width*0.1f,Screen.height*0.1f,Screen.width-Screen.width*0.2f,Screen.height-Screen.height*0.5f);
GUI.Box(demoArea,"SUBMIT SCORE");
GUI.BeginGroup(demoArea);
GUI.Label(new Rect(10,50,80,25), "Name: ");
GUI.Label(new Rect(10,90,80,25), "Score: ");
name = GUI.TextField(new Rect(120, 50, 150,25), name,14);
GUI.Label(new Rect(120, 90, 80, 25), score.ToString());
GUI.EndGroup();
}
//CONDITION 1: DISPLAY WINDOW FOR DATA FROM PHP-------------------->
if(gamecon.hiScoreSection==1){
windowRect = GUI.Window(0, windowRect, DoMyWindow, WindowTitel);
}
}
//DATA FOR CONDITION 1 TO DISPLAY-------------------->
void DoMyWindow(int windowID){
GUI.skin = Skin;
GUI.Label (new Rect (windowWidth / 2 - windowWidth / 2, 70, windowWidth, windowHeight), Score);
}
//NEEDED TO COMMUNICATE WITH PHP-------------------->
public string Md5Sum(string input){
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++){
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
}
Thanks for any help. Peace. ![]()

