Hey everyone!
I’m looking to create a login system into a game, however I’ve looked all over to find a way of connecting to a MySQL database (from client) just with no luck. The only thing I can currently think of is use WWW() and post the login information to a php file and return the account information as an array which would then get turned into seperate private/static variables. This way seems a bit crude so am I missing something here?
Thanks alot guys!
It’s far from crude. Another layer of abstraction between your user and a database is a good thing, far safer than opening a port for ODBC connections on your machine to the world.
Let anyone who feels like it access your database and how long you think it’ll be before someone sends it “SELECT * FROM USERTABLE ORDER BY USERNAME” or something similar?
You can find a good example of Unity/PHP/SQL interaction by looking at the high scores example on the wiki.
As Quietus mentions, there is no way to provide open database access to clients without getting into a lot of trouble. Pass it through a server-side application layer first.
Wow thanks alot guys - I’m sure I’ll be reading that highscores example quite a lot
I’ve also got a second question - Is it possible to get the location of a click on the terrain and then move a player to that point?
LukeB, take a look here for the PHP + MySQL + Unity:
http://forum.unity3d.com/viewtopic.php?p=166598#166598
And a project that has the comands you want to move units:
http://forum.unity3d.com/viewtopic.php?t=18802
What about accessing MYSQL via an authoritative server? That’s not a security risk. How would that be done without a PHP layer (which is too slow)? Only through SmartFox?
I would try to use SFS yes…
Actually, I will start to try out SFS in the next month
Through whatever you want basically as long you are able to develop the backend.
Be it SFS, Neutron, your own TCP redirection server or whatever.
Benefit of a PHP (or for realtime potentially better ruby on rails / CGI ) is that you don’t need a dedicated linux / windows machine, a normal webhost does the job
My server is going to run a Unity exe. How do I access MYSQL from that?
You have to make a script using, for example, the WWW class, inside your game and it will comunicate with a server, like Dreamora said, running in a webhost (like I do)… the little tutorial I did explain this. It is a login system with a MySQL database inside a webhost, very simple.
For MySQL from within a Unity client, check out the .NET database connectivity.
The mono / .NET documentation will help you on that as it is not related to unity.
But be aware that Unity uses Mono 1.2.5, which is neither a “MS .NET” nor is it the current mono so you will potentially find out that some of the things don’t work as you expect.
Question though is what kind of a server you want to do with Unity. I ask because you must never forget that you will not be able to put hundreds of users in a single unity client that you use as server.
Firstly, why not? I though Unity was supposed to handle MMO-style projects.
Secondly, how else would it be done? How would any other technology interact with Unity’s network views and syncronization?
I’m not going to write my own C++ server. I was under the impression that SmartFox could run servers with 1000+ clients. I could theoretically write a Java server but how would that interact with Unity clients? I want to stay as high-level as possible.