Hi, I cant figure out how to get the player name from my game to the HSController script.
I have… var name: String = “”;
and
To get the players name… name.text = getPlayN.player1;
But i keep getting: Ambiguous reference ‘name’: HSController.name, UnityEngine.Object.name.
#pragma strict
private var secretKey: String = ""; // Edit this value and make sure it's the same as the one stored on the server
var addScoreUrl: String="http://localhost/unity_test/addscore.php?"; //be sure to add a ? to your url
var highscoreUrl: String="http://localhost/unity_test/display.php";
var name: String = "";
var nameText: UILabel;
var score: int;
var scoreText: UILabel;
var loadingText: UILabel;
var getPlayN : CashCountGemCount;
function Awake(){
getPlayN = GameObject.FindWithTag("CashNGems").GetComponent(CashCountGemCount);
score = CashCountGemCount.kills;
}
function Start() {
getScores();
}
function GetPlayersInfo(){
yield WaitForSeconds(0.2);
name.text = getPlayN.player1;
nameText.text = getPlayN.player1;
scoreText.text = ""+CashCountGemCount.kills;
}
function postScore(name:String, score:int) {
//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.
var hash=md5functions.Md5Sum(name + score + secretKey);
var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;
// Post the URL to the site and create a download object to get the result.
var hs_post = WWW(highscore_url);
yield hs_post; // Wait until the download is done
if(hs_post.error) {
print("There was an error posting the high score: " + hs_post.error);
}
}
// Get the scores from the MySQL DB to display in a GUIText.
function getScores() {
loadingText.text = "Loading Scores";
var hs_get = WWW(highscoreUrl);
yield hs_get;
if(hs_get.error) {
print("There was an error getting the high score: " + hs_get.error);
} else {
loadingText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}