J'ai une application dans laquelle j'ai un bouton qui appelle une pub Quand je test dans l'editor de Unity, pas de soucis et j'ai la pub test de Admob qui s'affiche mais quand je test cela dans le build (en ayant renseigner mon smartphone comme appareil de test ET en utilisant un appID de test) rien ne s'affiche.
Voici le script C# qui appelle la pub :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class AdMobAd : MonoBehaviour
{
private InterstitialAd interstitial;
string adUnitId = "ca-app-pub-XXXXXXXXXX/XXXXXXXX";
// Start is called before the first frame update
void Start()
{
MobileAds.Initialize(initStatus => { });
//RequestInterstitial();
}
// Update is called once per frame
void Update()
{
}
public void RequestInterstitial()
{
//#if UNITY_ANDROID
//string adUnitId = "ca-app-pub-3940256099942544/1033173712";
//#elif UNITY_IPHONE
//string adUnitId = "ca-app-pub-3940256099942544/4411468910";
//#else
//string adUnitId = "unexpected_platform";
//#endif
// Clean up interstitial before using it
if (interstitial != null)
{
interstitial.Destroy();
}
// Initialize an InterstitialAd.
this.interstitial = new InterstitialAd(adUnitId);
// Called when an ad request has successfully loaded.
this.interstitial.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
this.interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is shown.
this.interstitial.OnAdOpening += HandleOnAdOpened;
// Called when the ad is closed.
this.interstitial.OnAdClosed += HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
//this.interstitial.OnAdLeavingApplication += HandleOnAdLeavingApplication;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLoaded event received");
}
public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
MonoBehaviour.print("HandleFailedToReceiveAd event received with message: "
/*+ args.Message*/);
// Handle the ad failed to load event.
}
public void HandleOnAdOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}
public void HandleOnAdClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdClosed event received");
}
/*public void HandleOnAdLeavingApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLeavingApplication event received");
}
*/
}
Bien à vous,
Bilu