i have an unity app project where i have included gley‘s advertising asset plugin „mobile ads“.
i use this plugin to display admob and unity ads in the defined mediation order that i want to set.
however i followed gley‘s documents how to initiate the ad calls and everything works well.
my problem now is, that i have added a ad call to run an interstitial ad showing everytime a user pushes a reset button.
but in my game this button is pressed very often and the users get to see the interstitial ads way too often (this button is pressed 3-4 times per minute).
my question is, could you help me to find out how to set a counter/time so that the ads are only called every x time that the button is pressed?
You can obtain the current time with System.DateTime.Now.
You can store it however you like, either in a GameManager or a static variable, something to track “last time ad shown.”
On subsequent attempts to show an ad you can check that time again, then use the System.DateTime.Subtract() method (with the “last time ad shown” variable) to see how much time has passed since the last ad set.
Based on that span you can decide if it is time to show a new ad.
And obviously if you do, you would store that time in the “last time ad shown”
If the random number generator returns the value 3 many times in a row, the user will suddenly get a burst of ads, and then if it doesn’t return a 3 for a long time, the user will see no ads.
If you consider that “working”, then yes it will work.
Certainly. Increment an integer somewhere that persists the length of the game, and when it reaches 3, do two things: set it back to zero and show your advert.
You can make the integer static to trivially easily do it, but it will still return to zero the next time you launch.
If you need it to persist from session to session, use PlayerPrefs, perhaps something like:
Here’s an example of simple persistent loading/saving values using PlayerPrefs: