Hi!
In my game I would like to the user an ad after he/she completed a game session a number of times. So first I show him/her an ad after 3 games, and then after every games where the number of games is divisible with 6.
If an ad is coming up, first I show a please wait… screen for the user. This screen will be up for 1 seconds to make the user “prepared” and not click anymore. If the ad is ready it will show up, if not then I change the screen for a game over one.
I have a UnityAdsController script with this code:
public bool ShowInterstitialVideoAd()
{
if (Advertisement.IsReady("video"))
{
Advertisement.Show("video");
return true;
}
else
{
return false;
}
}
Then I have a LevelManager script with this code:
IEnumerator ShowVideoAdCoroutine()
{
yield return new WaitForSeconds(1.0f);
if (!gameController.ShowUnityVideoAd())
{
gameOverObjectsScript.EnablePleaseWaitAdTextObject(false);
gameOverObjectsScript.EnableGameOverScreenObjects(true);
}
else
{
gameOverObjectsScript.EnablePleaseWaitAdTextObject(false);
gameOverObjectsScript.EnableGameOverScreenObjects(true);
}
StopCoroutine(ShowVideoAdCoroutine());
}
It would be responsible for showing the ad after the 1 second elapsed. I start the coroutine if the correct number of games have been played, with this piece of code:
if (gameController.GetNumberOfGamesCompleted() == 3 || (gameController.GetNumberOfGamesCompleted() % 6 == 0)) {
gameOverObjectsScript.EnablePleaseWaitAdTextObject(true);
gameOverObjectsScript.EnableGameOverScreenObjects(false);
unityAdsShowCoroutine = StartCoroutine(ShowVideoAdCoroutine());
}
My question is, would it be a correct implementation as I do it now? Wouldn’t the coroutine mess up with the ad showing up?
Thanks in advance!