Hey guys, having some difficulties here. I’m trying to make a level list on my game. I have it working pretty well but I can’t get a button to appear after each listing (to play the level). Here’s what my script looks like…
var lvl_get = WWW("http://www.coreymccown.com/Unity/BallGame/levellist.php");
yield lvl_get;
if(lvl_get.error) {
print("There was an error getting the level list: " + lvl_get.error);
} else {
LevelsText = lvl_get.text; // this is a GUIText that will display the level list
}
I’m a bit confused: what do you want this script to do? It appears to be sending a string to Unity, and you’re displaying it on the screen. If you want a button to show up, you’ll need to code that in. You might want to parse the string into chunks: one that gives the level name, one for the description, one for the rating, then put a button after each. GUILayout would be an easy way to do it.
The script is sending a string to Unity, yes. It displays everything (for the most part) how I want it to be displayed, but I want to be able to code the button on the PHP script, so where it says GUILayout.Button(“Play”) I plan on making that have the level ID and to play it, but in the game, it just comes up as text, not the button. I was hoping there was away to make that text be ran as a script, not the text… sorry for confusion.
That sounds like an over-complicated way of doing exactly what ncst said. If you know that every Level will be represented with three lines of text and then a button, you can just send the three lines of text and create a button in your game’s code. You don’t even need to parse the control type out of the input because this is such a simple problem (as opposed to generating different controls with varied parameters). You always know it’s a button, you always know what it says, and you can always define what the button does with a string or number sent in the PHP string.
Split the lines up in your game script, loop through them, and draw a button after each one.
You’re absolutely right! I dunno why my thick head didn’t comprehend this. Duh! Thanks! I’m trying to figure it out now… though I’m not sure where to start lol
If I were doing this (and I’m sure there are better ways), I might use symbols to separate each field (like ), and then a symbol to separate each level (like |):
Let’s say you send this string from your php script: Level One&Testing this thing2.5|Level Two&Another test3.0
Then use String.Split to split the string on the | to get an array of strings. Then, for each string, split on to get the fields. You should get a string array with 3 elements for each level.