Hello
I was wondering what is the best way of saving the players name,points,score whatever else I need.
I was going to use PlayerPref but I just found out that players can edit them since they are mostly used for testing/debug purposes.
I also thought of using databases with php but not sure how I could retrieve from the database only certain columns.
For example I create a table that holds (name,points,score), how I would be able to put in a GUI.Label only the score without the name and points.
Also if I use PlayerPref how easy would it be to edit them and how are other games(or your game) storing things like this?
Anything you use will generally be super easy to hack unless you encrypt the data. Then it’s still hackable but much harder.
Easy option: Save a hash of your save data. When you load the data, generate a hash again. If the hash has changed, then you know the save data has been tampered with.
Pro option: Use the Cryptography namespace to encrypt your data. Then write the encrypted data to a JSON file or something similar.
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
[Serializable]
class MyUserData
{
public int score;
public string name;
}
void SaveGame(MyUserData data, string filePath)
{
var fp = File.OpenWrite(filePath);
var serializer = new BinaryFormatter();
serializer.Serialize(fp, data);
fp.Close();
}
MyUserData LoadGame(string filePath)
{
var fp = File.OpenRead(filePath);
var serializer = new BinaryFormatter();
var ret = serializer.Deserialize(filePath) as MyUserData;
return ret;
}
However, I’m unsure if this will work on android - feel free to give it a shot, though.
Hammil’s option is much easier! And it’ll block anyone who doesn’t know how to use a hex editor quite well. And if they can use a hex editor… how secure do you really need to keep a score?
Well so far I don’t really need to keep anything secured since the game is singleplayer and you can only enter your name and the score is entered at the end of the round.
But further on I want to add score and with the score you will be able to customize the character.
Also how would you edit the PlayerPref?
I found my data folder and inside I had com.. which are the ones I gave to my game and I found a cache file. Is the what you need to edit for PlayerPref?