- Home /
Save gamedata to database (playerprefs)
Hi!
I have a little project doing a 2d game in Unity. My game idea is to complete the level as fast as you can. I have accomplish the time label in to the game but i don´t know how to save it in to a database. I have seen people using playerprefs.
Is that something I should use?
My next question is if I can use somekind of database to store my timescore? I have limited knowledge about sql server.
I would be grateful for answers :)
Answer by TonyLi · Mar 12, 2014 at 02:35 PM
PlayerPrefs is designed to save small amounts of data locally. It's ideal for saving game settings (e.g., audio volume, key bindings, etc.) and high scores. Example:
void SaveTimescore(string timescore) {
PlayerPrefs.SetString("Time Score", timescore);
}
string GetTimescore() {
return PlayerPrefs.GetString("Time Score");
}
In Windows, this data is in a registry entry that's only supposed to be accessed through a Unity application. Since you want to store it in MS SQL Server, you can use this "Beginner's guide to accessing SQL Server through C#" tutorial in your Unity app and your MVC app.
Do you really think high score should be in player's preference ? I mean if you have a game of 100 different levels with a high score for each one.
I am interesting in your point of view.
Why not? 100 scores isn't a lot of data. It really just depends on the game. If you only need to save a small amount of data locally, it's a quick and easy cross-platform method. If you want to $$anonymous$$imize the number of entries in PlayerPrefs you can store everything in one string -- for example, using a comma-separated string of scores, or serializing to JSON or X$$anonymous$$L.
I understand your point and I agree. I was just thinking in an Android (with Unity of course) app. Player's preferences can be removed on the phone.
But it depends on what you want to do with your data ^^.
Thank you for your reply, it always is interesting to get other points of view.
Is PlayerPrefs survive when we update the game in Play Store? (As long as user don't uninstall it.)
Answer by livevlad · Mar 12, 2014 at 12:45 PM
Hello,
I do not think that player's preferences are really to save scores.
You could use local files or a database. I would advise you SQLLite which is a local database (you do not need a server).
Check that : http://wiki.unity3d.com/index.php/SQLite SQLite is a very common technology, you should find a lot of tutorial even for Unity project.
Hope it helps !!!
Nice thanks :) In a matter of fact this game is for a school project. $$anonymous$$y $$anonymous$$cher have a requirements specification that it must contain a databaseconnection. So my idea was a timescore that stores in my database (that i have created in $$anonymous$$icrosoft sql management studio).
The main problem is that i like to view the highscorelist in a mvc-application.
Do you know how i can make that kind of connection to work out?
When commenting on someone's answer, please click the "add new comment button under their answer ins$$anonymous$$d of posting your response as a new answer.
It seems to be the following architecture : Clients (Unity), server with database and Ad$$anonymous$$ part to view the list of high scores or something on browser.
I do not know if Unity have a special way to connect this kind of Database. Try to find classic tutorials about database connection in c# and software you use.
Answer by BytesCrafter · Feb 02, 2017 at 06:42 PM
"United Database - Multi Platform Implementation" The first ever software of BytesCrafter. Visit our website for more info. Email us at bytescrafter@gmail.com. But if your on mobile, maybe you can use the google play game services. Yet, the bad part is that it is only available on mobile. The advantage of having your own database is that you can used it on many platforms that has an access to the internet. So, as of now we are currently making ways to minimized implementation for developers. May I invite you to our newest release of "United Database" that will be hosted on our site, dont worry its FREE. The idea is to have a unified database for your mobile and other platforms and also you can check for all the players currently registered and active. Please check the link and email us if you have any comments or suggestions: http://bytescrafter.weebly.com/database.html You know, the advantage of database is limitless. It really depends on how you used it but in general purpose. You used database for saving and loading player prefs / progress, For example, you can save your player level, experience, etc. and also, if you want to contact your player such as email ad, and another thing is when you want to see stats of your game. There are so many application for database, what you need is to think like a player. It also brings loyalty from the players as their progress can be continue, just by sharing, we are almost done with the "United Database", which in our mind, we want to deploy our games in multiplatform to have a greater chance of having more players. Supported Platform: Android, Apple IOS, Windows Phone, Smart TV, HTML5/WebGL, Windows, Apple Mac, Linux, Playstation, Xbox, Steam, Facebook Canvas, Itch.io, and many more to come including website. This software will have a flexible plan to developers, yet the software will be distributed for free with unlimited database entry but maximum database capacity of 3. #BytesCrafter #GameDevelopersOfUnity #IndieGameDeveloper #IGDA#CSharp #Php #MySQL #Database #UnityTechnologies