Search Unity

Advertisement Package 3.4.0, how do I tell it to load an Ad before displaying?

Discussion in 'Unity Ads & User Acquisition' started by JustAnotherDude, Dec 10, 2019.

  1. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    279
    The documentation at https://docs.unity3d.com/Packages/com.unity.ads@3.4/manual/MonetizationBasicIntegrationUnity.html is not clear.

    We have to implement IUnityAdsListener, it has 4 callbacks :

    Code (CSharp):
    1.     public void OnUnityAdsReady(string placementId)
    2.     {
    3.         throw new NotImplementedException();
    4.     }
    5.  
    6.     public void OnUnityAdsDidError(string message)
    7.     {
    8.         throw new NotImplementedException();
    9.     }
    10.  
    11.     public void OnUnityAdsDidStart(string placementId)
    12.     {
    13.         throw new NotImplementedException();
    14.     }
    15.  
    16.     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    17.     {
    18.         throw new NotImplementedException();
    19.     }
    The only thing we can do is call Initialize:

    Code (CSharp):
    1.     Button myButton;
    2.     public string myPlacementId = "rewardedVideo";
    3.  
    4.     void Start () {  
    5.         myButton = GetComponent <Button> ();
    6.  
    7.         // Set interactivity to be dependent on the Placement’s status:
    8.         myButton.interactable = Advertisement.IsReady (myPlacementId);
    9.  
    10.         // Map the ShowRewardedVideo function to the button’s click listener:
    11.         if (myButton) myButton.onClick.AddListener (ShowRewardedVideo);
    12.  
    13.         // Initialize the Ads listener and service:
    14.         Advertisement.AddListener (this);
    15.         Advertisement.Initialize (gameId, true);
    16.     }
    Then our button will call :

    Code (CSharp):
    1. // Implement a function for showing a rewarded video ad:
    2.     void ShowRewardedVideo () {
    3.         Advertisement.Show (myPlacementId);
    4.     }

    The button is only activated if we received the OnUnityAdsReady event. However there is no LoadAd method, is the Ad downloaded when we call Initialize only?

    What happens if we want to display the ad a second time? We have to destroy this gameobject and call initialize again?

    How do I tell the Advertisement API to load a new ad after the player watched one ad? Cause if 1 ad comes the button will activate and nothing says that the OnUnityAdsReady event will be called again.
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    The Unity Ads SDK automatically loads a new ad in two situations: during initialization and while an ad is currently playing.

    The OnUnityAdsReady event will be called for each new placement that becomes ready. You can disable the button when you click it and then re-enable it once a new ad is ready.
     
    JustAnotherDude likes this.