- Home /
Finish setup php, how to communicate with mySQL and unity
I have already set up the php (using WAMPServer) and now my problem is how am i going to make my php communicate with unity? Would appreciate if there is people who can help out.
http://www.unifycommunity.com/wiki/index.php?title=Server_Side_Highscores
Answer by ByteSheep · Mar 27, 2012 at 03:04 AM
PHP doesn't communicate with unity, but unity can change the url of the page and PHP can then pick up variables stored in the url using the $_GET[] function.
The link you posted is well documented - Basically HSController.js is the script that sets and gets the highscores; display.php is the script that gets the data from the database; and addscore.php adds data (scores, playername, etc) to the database.
Everything that you need is explained and provided in the tutorial, but let me know if there is a specific problem you are encountering ;)
Actually like i mention, i have already setup the php file. Now what i want to do is store my data from Unity to mySQL. I am not storing score, thatwise i find it rather hard to continue from there. I want to store the click that the player have click on. For example, player click on APE, i will need to store 'APE' into the column. Something like that.
The file that you'd need to edit is the HSController.js script. The function that you need to edit is the postScore() function, which is currently taking two parameters: name and score. You will basically have to edit this to reflect your purpose.. You then will also have to change the mysql table structure etc (if you haven't already) and make some edits to the given php files. The process is the same but you just need to edit change the variables that are sent to and taken from the server. It's not easy to explain..
Answer by rutter · Mar 27, 2012 at 03:09 AM
The examples you're linking to use Unity's WWW class to communicate with a high score server.
Unity can use WWW to send an HTTP GET request with a special URL containing some data.
The server can read parameters from the GET request, update internal state as needed, and reply with relevant information. In this case, it looks like you're using a webserver set up with PHP and MySQL.
Back in Unity, you can parse the returned information and display it for your end user.
Is there a specific part of this process that you're having trouble with?
Yes. So basically what i want is, Unity capture all the data player have clicked(for instance, player click on 'APE'), then i want all the click to be store into the database. I not very sure do i need WWW class. Because from my research, it is shown that php-> Server-> Unity. Sorry if i am wrong. I am still quite confused.
You need a client (Unity) and a server (PHP). These are completely separate applications, but they need to be able to talk to each other.
You can collect as much data as you want, in Unity, but it won't do you much good if you don't eventually push it up to your server. Likewise, your server won't be much use unless it's able to send data back to your Unity clients.
You're welcome to implement client-server communication in any way you please. Unity's WWW class is a simple and relatively straightforward method of doing so, on the client-side.
Ultimately, you're dealing with a very large problem that some people study for years. If you want a silver bullet solution that you can build in a matter of $$anonymous$$utes, you're just not going to find one. That's why I'm asking if you're having trouble with a specific, actionable item.