online highscore unity 5.1
I want to make just a display part but i didnt fix it these errors.
Assets/HSController.cs(20,23): error CS1061: Type UnityEngine.GameObject' does not contain a definition for
text' and no extension method text' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
Assets/HSController.cs(30,31): error CS1061: Type UnityEngine.GameObject' does not contain a definition for
text' and no extension method text' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
using UnityEngine; using System.Collections;
public class HSController : MonoBehaviour { public string highscoreURL = "http://localhost/display.php"; public GameObject text1; public GameObject text2;
void Start()
{
StartCoroutine(GetScores());
}
// Get the scores from the MySQL DB to display in a GUIText.
// remember to use StartCoroutine when calling this function!
IEnumerator GetScores()
{
text1.text = "Loading Scores";
WWW hs_get = new WWW(highscoreURL);
yield return hs_get;
if (hs_get.error != null)
{
print("There was an error getting the high score: " + hs_get.error);
}
else
{
text2.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
}
Answer by toddisarockstar · Jul 31, 2016 at 03:46 AM
the responce actually comes back in a byte array format so if you are expecting a string or text responce from your server you must convert it before it's understandable text again. here's how i like to get responces.
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
WWW hs_get;
public void Start(){
hs_get = new WWW ("your URL goes here!!!!!!!!");
}
public string score;
public void Update() {
if(score==""){if(hs_get.isDone){
if(hs_get.error==null){
score=System.Text.Encoding.UTF8.GetString(hs_get.bytes);
print(score);
}else{print("i got an error from server saying "+hs_get.error);score="Error";}
}}}}
Your answer
Follow this Question
Related Questions
how to implement online leader board to my project? 0 Answers
A way to move "Highscore" Text to Game Over Screen? 1 Answer
Highscore Not Updating Upon Death 1 Answer
how do i store highscore locally C# (SIMPLE) 3 Answers
GUI Highscore? 0 Answers