I would like the players of my game to be able to unlock promotional content and other special stuff by entering single-use key codes. How do I do this with Unity? How to generate the codes? And how can I check if the code has already been used by someone else?
Thanks in advance.
Well, to keep track of which codes are used, and which are still usable, you need to have some sort of central online database.
To actually generate a key, several methods can be used. Just taking the name of the game in a string, salting it with the timestamp and some other cool nonsense characters makes a pretty good base for fiddling around with. Example being “My wonderful game” + “1335875079” + “AfeWExtRaChaRAcTers”
And what I mean by fiddling around is to change letters and numbers and possibly even special characters around with the help of an algorithm. It could be as simple as a substitute algorithm, where you replace all A’s with B’s and all 1’s with 2’s, or as complex as the SHA-1.
Or if you generate the keys on demand, you could just randomize 30 characters, see if it already exists in the database and if it doesn’t, insert it. It’s a bit less secure though, since people could actually make their own keys and even though they can’t enter them into your database, they might get lucky and steal someone else’ code.