Search Unity

About AR Ads

Discussion in 'Unity Ads & User Acquisition' started by usul1886, Mar 7, 2019.

  1. usul1886

    usul1886

    Joined:
    Jan 17, 2017
    Posts:
    1
    Hi,

    I have a question regarding AR Ads implementation on Unity, I've been asked to implement the code needed to show an Unity Ad into a project, and that ad would be an AR Ad, my doubt comes when seeing the example code for implementing a basic non-rewarded ad

    Code (CSharp):
    1. using UnityEngine.Monetization;
    2.  
    3. public class UnityAdsPlacement : MonoBehaviour {
    4.  
    5.     public string placementId = "video";
    6.  
    7.     public void ShowAd () {
    8.         StartCoroutine (ShowAdWhenReady ());
    9.     }
    10.  
    11.     private IEnumerator ShowAdWhenReady () {
    12.         while (!Monetization.IsReady (placementId)) {
    13.             yield return new WaitForSeconds(0.25f);
    14.         }
    15.  
    16.         ShowAdPlacementContent ad = null;
    17.         ad = Monetization.GetPlacementContent (placementId) as ShowAdPlacementContent;
    18.  
    19.         if(ad != null) {
    20.             ad.Show ();
    21.         }
    22.     }
    23. }
    and seeing the example code for an AR Ad

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Monetization;
    3.  
    4. public class ARTest : MonoBehaviour {
    5.     private PlacementContent MyPlacementContent;
    6.  
    7.     void Start () {
    8.         Monetization.Initialize ("1234567", false);
    9.         Monetization.onPlacementContentReady += PlacementContentReady;
    10.     }
    11.  
    12.     public void ShowAd () {
    13.         if (MyPlacementContent != null) {
    14.             ShowAdPlacementContent ad = MyPlacementContent as ShowAdPlacementContent;
    15.             ad.Show (myAdCallbackHandler); // See note on callback handlers, below
    16.         }
    17.     }
    18.  
    19.     public void PlacementContentReady (object sender, PlacementContentReadyEventArgs e) {
    20.         Debug.LogFormat ("PlacementID: {0}, Object: {1}", e.placementId, e.placementContent.GetType ());
    21.         if (e.placementId == "arPlacement") {
    22.             MyPlacementContent = e.placementContent;
    23.         }
    24.     }
    25. }
    they do the same thing in different ways, in the basic non-rewarded ad example you can just get the ad for the placement you want to, and in the AR Ad example you get all of the placements and if the placement id is the one for the AR Ad then it gets assigned to a variable of the PlacementContent type, which later gets casted into a ShowAdPlacementContent type, my question is the following, does the basic non-rewarded ad code works for AR Ad too?
     
    RobertoL likes this.