- Home /
How to display Interstitial Ads after a set number of plays
I have integrated Chartboost to my project and I am trying to display an ad when a user loses. I have created a CreateAd method in a script and I am calling it whenever the user loses and gets the game over screen.
public void CreateAd () {
CBBinding.showInterstitial(null);
}
But I want to count how many times a user has played in a single sitting and display an ad every five plays or so. Not every time. Also could someone please show me how to check if Chartboost is available and if not use a different ad service like Admob or inMobi?
The first part of your question is simple enough: create a static variable, and add one to it each time the player restarts a level.
//use the "modulo" operator to check for multiples of five
playCount++;
if (playCount % 5 == 0) {
//do something
}
The second part I'm less familiar with. That seems pretty specific to the specific plugin(s) you're using.
Answer by smallbit · Jul 16, 2014 at 02:10 PM
First answer as posted by rutter. I use to display add every x games unless player reached some minimum result
playCount++;
if (playCount % 5 == 0 || result>1000) {
//do something
playCount = 0; // reset the counter
}
As for the second part, chartboost api has the flag hasCachedInterstitial
if(CBBinding.hasCachedInterstitial(null))
{
CBBinding.showInterstitial(null);
}
You can also listen to delegate public static event Action didCacheInterstitialEvent;
which is fired once ad is cached. more info about it here Chartboost unity manual
Does anyone know how to do the same thing, but in C# and Unity ads?
Your answer
![](https://koobas.hobune.stream/wayback/20220613154054im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do Smart Banners scale? 0 Answers
My game has low FPS on iPhone 5 but not Android... 0 Answers
Optimal # of Faces for many mesh scene for mobile 1 Answer
Can't click Ads with AdMob 1 Answer