- Home /
Problem with WWW
Hi everyone,
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 am I doing wrong?
Answer by Bunny83 · Sep 01, 2012 at 03:14 AM
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.
So please be more specific.
Sorry about the misunderstanding, I've edited the post with extra details on what doesn't work.
Your version of the code doesn't work either, I still get the error "text is not a member of the Unity class WWW"... Perhaps it is just my version of Unity?...
Well this error is usually caused by one of your classes which is also named WWW. $$anonymous$$ake sure you don't have any file named "WWW.js" in your project. It will hide the WWW class that is inside the UnityEngine namespace. If you're not sure where that file is, you can quick test it by replacing "WWW" in your script above with "UnityEngine.WWW". This will force the compiler to use the WWW class from the UnityEngine namespace.