I have implemented Unity Ads to my soon-to-be published application, however I see an interesting thing with un-rewarded ads. When game over is called in my game and I didn’t show any rewarded ads to my user, I would like to show them a normal video ad.
The code what I call looks like this:
if (shouldYield)
{
SaveGame();
if ((numberOfGamesPlayed != 0) && (numberOfGamesPlayed % 5 == 0))
{
Advertisement.Show("video");
}
yield return new WaitForSeconds(2.0f);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
SaveGame(); saves the users progress to a json file and does nothing else.
After that if it’s not the first game of the user, and the games he played can be divided by 5, I would like to show him/her a video ad, then after the ad returned wait 2 seconds and load a “new” scene.
It works as it should, except the few times it loads two ads after each other instead of one. It happens in the editor and in the android build too (with test mode). I couldn’t reproduce why the issue is happening, so I thought I would ask it here if it’s happening to others too, or if my code causes this.
I forgot to say that, sorry. When my character collide with an enemy (OnCollisionEnter), a method get called which then calls an IEnumerator method with the shouldYield parameter. As far as I know it shouldn’t be called more than one times from here.