简体   繁体   中英

Unity Admob - AdRequest the right way

I change the demo script and it works for me:

using GoogleMobileAds.Api;
…
void Start(){
    RequestInterstitial();
}

private void RequestInterstitial()
{
    #if UNITY_EDITOR
        string adUnitId = "unused";
     #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxx";
     #elif (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
        string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create an interstitial.
    interstitial = new InterstitialAd(adUnitId);

    // Load an interstitial ad.
    interstitial.LoadAd(createAdRequest());
}

private AdRequest createAdRequest()
{
    return new AdRequest.Builder()
            .AddTestDevice(AdRequest.TestDeviceSimulator)
            .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
            .AddKeyword("game")
            .SetGender(Gender.Male)
            .SetBirthday(new DateTime(1985, 1, 1))
            .TagForChildDirectedTreatment(false)
            .AddExtra("color_bg", "9B30FF")
            .Build();
}



 public void endGame(){
        if (interstitial.IsLoaded())
        {
            interstitial.Show();
        }
    }

Now I want to remove the test device to use it on real work, all I need to make is to change the method createAdRequest() like this:

private AdRequest createAdRequest()
{
    return new AdRequest.Builder().Build();
}

That will work? There is some arguments that I need to put on the AdRequest? If I need to change something can someone give me a example?

Thanks

That will work?

Yes. Of-course, you could add SetGender , SetBirthday and other options but it should work. Once you are ready to deploy, simply remove the AddTestDevice() options which you you have already done in your question.

Anyways, I do not see you subscribing to the OnAdRewarded event. This function is called when an ad has finished showing. You can see how to do that here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM