Is it a correct implementation of non-rewarded video ad?

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!

@Zwiebel

I don’t see any reason why it wouldn’t work, but without testing I can’t be sure. I would recommend you test the code on a device to confirm that you are able to see test ads and your UI works as expected.

I think you might be able to simplify the code a bit if you used the IUnityAdsListener interface. This will allow you to get callbacks when the ads are finished, and you can just disable your wait screen there.
https://docs.unity3d.com/Packages/com.unity.ads@3.2/manual/MonetizationBasicIntegrationUnity.html#rewarded-video-ads

Thank you, I have reimplemented that part with IUnityAdsListener.