I am making a highscore board for my game, it uses a PHP script and a MySQL database. I have all the server side scripts working, but I’m having a bit of a problem retrieving the highscores with Unity and posting them to the game…
Here is the code I am using:
var targetGuiText : GUIText;
var myText : String;
var url = "https://yadayada.com/highscores.php";
function Start() {
var hs_get : WWW = new WWW (url);
yield hs_get;
myText = hs_get.text;
targetGuiText.text = myText;
}
This code doesn’t work… Whenever I run the game I get the error “text is not a member of the Unity class WWW”.
What do you mean by “does not work”? The script works perfectly, however i guess you want to display the returned text in your GUIText component… You just store the returned text in a local variable but you don’t assign it to the guiText component.
function Start()
{
var hs_get : WWW = new WWW (url);
yield hs_get;
targetGuiText.text = hs_get.text;
}
This works perfectly for me (with a meaningful uri of course since yours doesn’t respond at all. Was it just an example? If not are you sure the uri is correct? Keep in mind that most webservers are case sensitive, so http://example.com/test.php is not the same as http://example.com/Test.php or http://example.com/test.PHP)
You should explain your problem clearly and detailed. “Not working” can be anything…
Some possible “not workings”:
Does not compile do Unity won’t even run your game
The game crashes when you use the above code
It’s not doing what you would expect, in this case it would help to know what you would like expect.