Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

Discussion in 'Unity Ads & User Acquisition' started by Zwiebel, Aug 3, 2019.

  1. Zwiebel

    Zwiebel

    Joined:
    Jul 23, 2013
    Posts:
    56
    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:
    Code (CSharp):
    1. public bool ShowInterstitialVideoAd()
    2.     {
    3.         if (Advertisement.IsReady("video"))
    4.         {
    5.             Advertisement.Show("video");
    6.             return true;
    7.         }
    8.         else
    9.         {
    10.             return false;
    11.         }
    12.     }
    Then I have a LevelManager script with this code:
    Code (CSharp):
    1. IEnumerator ShowVideoAdCoroutine()
    2.     {
    3.         yield return new WaitForSeconds(1.0f);
    4.         if (!gameController.ShowUnityVideoAd())
    5.         {
    6.             gameOverObjectsScript.EnablePleaseWaitAdTextObject(false);
    7.             gameOverObjectsScript.EnableGameOverScreenObjects(true);
    8.         }
    9.         else
    10.         {
    11.             gameOverObjectsScript.EnablePleaseWaitAdTextObject(false);
    12.             gameOverObjectsScript.EnableGameOverScreenObjects(true);
    13.         }
    14.  
    15.         StopCoroutine(ShowVideoAdCoroutine());
    16.     }
    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:

    Code (CSharp):
    1. if (gameController.GetNumberOfGamesCompleted() == 3 || (gameController.GetNumberOfGamesCompleted() % 6 == 0)) {
    2.             gameOverObjectsScript.EnablePleaseWaitAdTextObject(true);
    3.             gameOverObjectsScript.EnableGameOverScreenObjects(false);
    4.  
    5.             unityAdsShowCoroutine = StartCoroutine(ShowVideoAdCoroutine());
    6.  
    7.         }
    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!
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @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/c...BasicIntegrationUnity.html#rewarded-video-ads
     
  3. Zwiebel

    Zwiebel

    Joined:
    Jul 23, 2013
    Posts:
    56
    Thank you, I have reimplemented that part with IUnityAdsListener.