- Home /
Limit number of run/executions
Is it possible to limit the number of times a game can be run? The equivalent of producing a full working demo but it expires after say 30 goes?
Answer by fafase · Mar 06, 2014 at 07:46 PM
On your first scene, add a script that runs something like this:
private int counter;
void Awake()
{
counter = PlayerPrefs.GetInt("Counter");
if(counter> 29)
{
Application.Quit();
}
else{
PlayerPrefs.SetInt("Counter", counter);
}
counter++;
}
For better control, you should store the information on a server but this s just for you to get the idea.
Also this solution is a little abrupt since it closes like this, pouf. You may want to warn the user.
Does the private int counter really not reset to null every time the program is restarted ?
PlayerPrefs store data into the registry on windows computers, so it will remain even through computer restarts. The last line should probably say counter+1
.
Is that value encrypted or could it be accessed and changed with a text editor ?
Also is it linked to the program by its name? Could the 30 execution expiry be circumvented by just changing the name of the program ?
I added the missing counter++, concerning the hack well there are ways to fix it until someone breaks it. One other way is to store in db with a login but then the user can create multiple logins. So I would think the time you will spend trying to find they ultimate way is not worth the result. $$anonymous$$any games comes with restrictions, like waiting for regeneration but simply changing the time on your device and you hack the game. Still they don't try and fix it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613135543im_/https://answers.unity.com/themes/thub/images/avi.jpg)