- Home /
php WWW not working in unity web player
Hi guys,
Got a problem with php in my game, it works in standalone player and mac osX version etc but does not work in the web player when built.
The game was built in to the same file as the crossdomain.xml and web server so I don't think that's the problem. And I am not using loops, I think I am using yield correctly. Any help would be much appreciated!
var highscoreUrl="http://localhost:8888/********/resources/get_score.php?";
public var stylish = new GUIStyle();
public var stylish2 = new GUIStyle();
public var stylish3 = new GUIStyle();
public var stylish4 = new GUIStyle();
function Start(){
var hs_get = new WWW(highscoreUrl);
yield hs_get;
if(hs_get.error) {
print("There was an error getting the high score: " + hs_get.error);
} else {
gameObject.guiText.text = hs_get.text; //this is a GUIText that will display the scores in game.
//formText = hs_get.text;
}
}
function OnGUI(){
if (GUI.Button(Rect(-70,0,250,40), "Main Menu" ,stylish2)){
Application.LoadLevel("MainMenu");
}
GUILayout.BeginArea (Rect(100, 70 ,Screen.width -200,80));
if (GUI.Button(Rect(0,0,200,40), "" ,stylish3)){
Application.LoadLevel("LeaderBoards");
}
if (GUI.Button(Rect(210,0,200,40), "" ,stylish4)){
}
if (GUI.Button(Rect(420,0,200,40), "" ,stylish)){
}
GUILayout.EndArea();
}
What isn't working? Are you seeing any warnings or errors in the console/debug log?
Thanks for the reply rutter,
The results from this query should appear in a GUI text, it works in unity3d player with no errors in console. But when I built this to my local server the results do not appear at all.
It seems like there is no interaction with the server? Sorry to be vague.
Try checking your error log file after running in browser. That could help you understand what is happening.
Cheers for the reply guys, I wasn't aware of the console.app!
I found this error -
There was an error getting the high score: Rejected because no crossdomain.xml policy file was found UnityEngine.Debug:Internal_Log(Int32, String, Object) UnityEngine.Debug:Log(Object) UnityEngine.$$anonymous$$onoBehaviour:print(Object) $:$$anonymous$$oveNext()
Where exactly should I put the crossdomain.xml file?
Please post your answer as answer and mark it as correct, so other can see that it is solved. Welcome to Unity Answers!
Answer by buxton4life · May 02, 2012 at 10:37 PM
SOLVED!
The cross domain policy needs to be utf encoded <?xml version="1.0" encoding="UTF-8"?>
also the file should be in the root or index of the web folder! Pretty basic mistake....thanks to Paulius Liekis and rutter for your input. :)
hey, I followed all the steps and I am getting absolutely no errors. though it works as an EX$$anonymous$$ The individual script that posts the data works well with .exe standalone as well as the we player builds. However if I run the game as web player, it does not work but surprisingly it works for .exe standalone build! I am having a hard time debugging this because there is no error printed as it was before, so ideally it should be working fine. But the data is not being written by the web player version of the game! Any suggestions of what I might be doing wrong? Thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070959im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I properly send binary data (byte[]) to a MySQL database? 4 Answers
WWW Request runs in Editor but not in Webplayer 1 Answer
Yield return request never returns 0 Answers
Retrieving data from a WWW php call? 1 Answer
Any caching options available for things dynamically loaded by WebPlayer? 0 Answers