Ads do not work. help me!

using UnityEngine;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class interfasemenu : MonoBehaviour {

public Font Fonte;

private string Som = "Lig.";

public static InterstitialAd interstitial;

private BannerView bannerView;

void Start(){

	Recorde2 = PlayerPrefs.GetFloat ("recorde");	

	interstitial = new InterstitialAd("ca-app-pub-xxxxxxxxxxxx");
	AdRequest request = new AdRequest.Builder().Build();
	interstitial.LoadAd(request);

	bannerView = new BannerView("ca-app-pub-xxxxxxxxxxxxxxx", AdSize.Banner, AdPosition.TopRight);
	AdRequest requestb = new AdRequest.Builder().Build();
	bannerView.LoadAd(requestb);

}

this is my startup code.It is the main menu and put the script on camera.

start the game, before it starts, opens a screen where the rules of the game are shown, and this screen I put the following code:

using UnityEngine;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class botaoregras : MonoBehaviour {

public Font Fonte;

void Start (){

	if (interfasemenu.interstitial.IsLoaded ()) {
		interfasemenu.interstitial.Show ();
	}

}

void OnGUI (){

	GUI.skin.font = Fonte;
	GUI.skin.button.fontSize = Screen.height / 16;

	if (GUI.Button (new Rect (Screen.width/2+Screen.width/4, Screen.height-Screen.height/5, Screen.width/5, Screen.height/8), "start")){

		Application.LoadLevel ("game");
		interfasemenu.interstitial.Destroy();
	}

already signed up the game in admob, created the building blocks of ads, and the reports says this with 11 requests. but the views are cleared.

already I tried everything and will not appear the ads. Can anyone help me?

A couple of tips:

  • Are testing it in device ? Please use device for ads testing instead of unity editor
    (if it is the case).

  • You wrote this in Start function:

    if (interfasemenu.interstitial.IsLoaded ()) {
    interfasemenu.interstitial.Show ();
    }

It is possible that Ads is not loaded yet, so the if condition will fail. Use Admob delegates in interfasemenu to use this condition, like:

public static void HandleInterstitialLoaded(object sender, EventArgs args)
{
    print("HandleInterstitialLoaded event received.");
    ShowInterstitial();
}

Hope it helps!

EDIT

Based on your comment you can check this demo script GoogleMobileAdsDemoScript.cs available here: GitHub - googleads/googleads-mobile-unity: Official Unity Plugin for the Google Mobile Ads SDK

The event i highlighted is included in this script. Please use this script.

  • Change Admob ids in the script.
  • Adjust the event i highlighted. So once the ad loaded successfully only then show it.
  • Attach this script to camera. (for example)
  • From your script, just call:

Camera.main.GetComponent<GoogleMobileAdsDemoScript>().RequestBanner(); Camera.main.GetComponent<GoogleMobileAdsDemoScript>().RequestInterstitial();

Make RequestBanner and RequestInterstitial as public functions in the script.

I hope then you are good to go.

using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class GoogleMobileAdsDemoHandler : IInAppPurchaseHandler
{
private readonly string validSkus = { “android.test.purchased” };

//Will only be sent on a success.
public void OnInAppPurchaseFinished(IInAppPurchaseResult result)
{
    result.FinishPurchase();
    GoogleMobileAdsDemoScript.OutputMessage = "Purchase Succeeded! Credit user here.";
}

//Check SKU against valid SKUs.
public bool IsValidPurchase(string sku)
{
    foreach(string validSku in validSkus) {
        if (sku == validSku) {
            return true;
        }
    }
    return false;
}

//Return the app's public key.
public string AndroidPublicKey
{
    //In a real app, return public key instead of null.
    get { return null; }
}

}

// Example script showing how to invoke the Google Mobile Ads Unity plugin.
public class GoogleMobileAdsDemoScript : MonoBehaviour
{

private BannerView bannerView;
private InterstitialAd interstitial;
private static string outputMessage = "";

public static string OutputMessage
{
    set { outputMessage = value; }
}

public void RequestBanner()
{
    #if UNITY_EDITOR
	string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxx";
    #elif UNITY_ANDROID
        string adUnitId = "INSERT_ANDROID_BANNER_AD_UNIT_ID_HERE";
    #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.TopRight);
    // Register for ad events.
    bannerView.AdLoaded += HandleAdLoaded;
    bannerView.AdFailedToLoad += HandleAdFailedToLoad;
    bannerView.AdOpened += HandleAdOpened;
    bannerView.AdClosing += HandleAdClosing;
    bannerView.AdClosed += HandleAdClosed;
    bannerView.AdLeftApplication += HandleAdLeftApplication;
    // Load a banner ad.
    bannerView.LoadAd(createAdRequest());
}

public void RequestInterstitial()
{
    #if UNITY_EDITOR
	string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxx";
    #elif UNITY_ANDROID
        string adUnitId = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE";
    #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create an interstitial.
    interstitial = new InterstitialAd(adUnitId);
    // Register for ad events.
    interstitial.AdLoaded += HandleInterstitialLoaded;
    interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad;
    interstitial.AdOpened += HandleInterstitialOpened;
    interstitial.AdClosing += HandleInterstitialClosing;
    interstitial.AdClosed += HandleInterstitialClosed;
    interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
    GoogleMobileAdsDemoHandler handler = new GoogleMobileAdsDemoHandler();
    interstitial.SetInAppPurchaseHandler(handler);
    // Load an interstitial ad.
    interstitial.LoadAd(createAdRequest());
}

// Returns an ad request with custom ad targeting.
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 ShowInterstitial()
{
    if (interstitial.IsLoaded())
    {
        interstitial.Show();
    }
    else
    {
        print("Interstitial is not ready yet.");
    }
}

#region Banner callback handlers

public void HandleAdLoaded(object sender, EventArgs args)
{
    print("HandleAdLoaded event received.");
}

public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    print("HandleFailedToReceiveAd event received with message: " + args.Message);
}

public void HandleAdOpened(object sender, EventArgs args)
{
    print("HandleAdOpened event received");
}

void HandleAdClosing(object sender, EventArgs args)
{
    print("HandleAdClosing event received");
}

public void HandleAdClosed(object sender, EventArgs args)
{
    print("HandleAdClosed event received");
}

public void HandleAdLeftApplication(object sender, EventArgs args)
{
    print("HandleAdLeftApplication event received");
}

#endregion

#region Interstitial callback handlers

public void HandleInterstitialLoaded(object sender, EventArgs args)
{
    print("HandleInterstitialLoaded event received.");
	ShowInterstitial();

}

public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
}

public void HandleInterstitialOpened(object sender, EventArgs args)
{
    print("HandleInterstitialOpened event received");
}

void HandleInterstitialClosing(object sender, EventArgs args)
{
    print("HandleInterstitialClosing event received");
}

public void HandleInterstitialClosed(object sender, EventArgs args)
{
    print("HandleInterstitialClosed event received");
}

public void HandleInterstitialLeftApplication(object sender, EventArgs args)
{
    print("HandleInterstitialLeftApplication event received");
}

#endregion

}

this is the code “GoogleMobileAdsDemoScript” where I put my adUnityid and put this script in camera.

then. in my script from the main menu interface. which also is in the camera. I put like this:

void Start(){
	Camera.main.GetComponent<GoogleMobileAdsDemoScript>().RequestBanner();
	Camera.main.GetComponent<GoogleMobileAdsDemoScript>().RequestInterstitial();
}

void OnGUI (){

	GUI.skin.font = Fonte;
	GUI.skin.button.fontSize = Screen.height / 16;
	GUI.skin.label.fontSize = Screen.height / 16;

	GUI.Label (new Rect (Screen.width/4-Screen.width/6, Screen.height/2+Screen.height/3,500,100), Recorde1 + Recorde2);

	if (GUI.Button (new Rect (Screen.width / 4 - Screen.width / 6, Screen.height / 2 + Screen.height / 16, Screen.width / 3, Screen.height / 7), "New Game")) {
				
		Application.LoadLevel ("game");
		Camera.main.GetComponent<GoogleMobileAdsDemoScript> ().ShowInterstitial ();

Neither the interstitial nor the Banner are working.

all scripts work normally, everything is in order, but sometimes I see this error in the console:

Asset ‘C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll’ is in timestamps but is not known in guidmapper…

can you be wrong?

I used the code you gave me and modified as you said. and I put it in the camera

then I put the script from my main menu, the following:

void Start(){

	Camera.main.GetComponent<GoogleMobileAdsDemoScript>().RequestBanner();
	Camera.main.GetComponent<GoogleMobileAdsDemoScript>().RequestInterstitial();
}

void OnGUI (){

	GUI.skin.font = Fonte;
	GUI.skin.button.fontSize = Screen.height / 16;
	GUI.skin.label.fontSize = Screen.height / 16;

	GUI.Label (new Rect (Screen.width / 4 - Screen.width / 6, Screen.height / 2 + Screen.height / 3, 500, 100), Recorde1 + Recorde2);

	if (GUI.Button (new Rect (Screen.width / 4 - Screen.width / 6, Screen.height / 2 + Screen.height / 16, Screen.width / 3, Screen.height / 7), "New Game")) {
				
		Application.LoadLevel ("game");
		Camera.main.GetComponent<GoogleMobileAdsDemoScript> ().ShowInterstitial ();

	}
}

I realized also that is showing the following error:

Timestamps (437) and assets (435) maps out of sync.

Asset ‘C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll’ is in timestamps but is not known in guidmapper…

will this be the problem?

Please i have the same issue, can someone please help me

public class ScoreScript : MonoBehaviour
{
    static public bool checkInter = true;
    static private int countCallIntUp = 0;

    void Awake()
    {
        RequestInterstitial();
        RequestBanner();
    }

    void Update()
    {
        if (checkInter == false)
        {
            ShowInterstitial();
            checkInter = true;
        }
    }

    IEnumerator OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            Physics.gravity = new Vector3(0, -9.81f, 0);
            countCallIntUp++;
            if (countCallIntUp == 3)
            {
                countCallIntUp = 0;
                checkInter = false;
            }
            other.gameObject.SetActive(false);
            yield return new WaitForSeconds(0.3f);
            SetCountText();
            imageScore.SetActive(true);

        }
    }

    //=========================================#
    // Google Ad Mob
    //public static string OutputMessage
    //{
    //    set { outputMessage = value; }
    //}

    public void BannerViewShow()
    {
        bannerView.Show();
    }

    private void RequestBanner()
    {
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
            string adUnitId = "ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxxxxxxx";
#elif UNITY_IPHONE
            string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
            string adUnitId = "unexpected_platform";
#endif

        // Create a 320x50 banner at the top of the screen.
        bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
        // Register for ad events.
        bannerView.OnAdLoaded += HandleAdLoaded;
        bannerView.OnAdFailedToLoad += HandleAdFailedToLoad;
        bannerView.OnAdLoaded += HandleAdOpened;
        bannerView.OnAdClosed += HandleAdClosed;
        bannerView.OnAdLeavingApplication += HandleAdLeftApplication;
        // Load a banner ad.
        //bannerView.LoadAd(new AdRequest.Builder().Build());
        bannerView.LoadAd(createAdRequest());
    }

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

        // Create an interstitial.
        interstitial = new InterstitialAd(adUnitId);
        // Register for ad events.
        interstitial.OnAdLoaded += HandleInterstitialLoaded;
        interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
        interstitial.OnAdOpening += HandleInterstitialOpened;
        interstitial.OnAdClosed += HandleInterstitialClosed;
        interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
        // Load an interstitial ad.
        //interstitial.LoadAd(new AdRequest.Builder().Build());
        interstitial.LoadAd(createAdRequest());
    }

    //Returns an ad request with custom ad targeting.
    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();
    }

    //    private void RequestRewardBasedVideo()
    //    {
    //#if UNITY_EDITOR
    //        string adUnitId = "unused";
    //#elif UNITY_ANDROID
    //            string adUnitId = "INSERT_ANDROID_REWARD_BASED_VIDEO_AD_UNIT_ID_HERE";
    //#elif UNITY_IPHONE
    //            string adUnitId = "INSERT_IOS_REWARD_BASED_VIDEO_AD_UNIT_ID_HERE";
    //#else
    //            string adUnitId = "unexpected_platform";
    //#endif

    //        rewardBasedVideo.LoadAd(new AdRequest.Builder().Build(), adUnitId);
    //    }

    private void ShowInterstitial()
    {
        if (interstitial.IsLoaded())
        {
            interstitial.Show();
        }
        else
        {
            print("Interstitial is not ready yet.");
        }
    }

    //public void ShowRewardBasedVideo()
    //{
    //    if (rewardBasedVideo.IsLoaded())
    //    {
    //        rewardBasedVideo.Show();
    //    }
    //    else
    //    {
    //        print("Reward based video ad is not ready yet.");
    //    }
    //}

    #region Banner callback handlers

    public void HandleAdLoaded(object sender, EventArgs args)
    {
        print("HandleAdLoaded event received.");
    }

    public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        print("HandleFailedToReceiveAd event received with message: " + args.Message);
    }

    public void HandleAdOpened(object sender, EventArgs args)
    {
        print("HandleAdOpened event received");
    }

    void HandleAdClosing(object sender, EventArgs args)
    {
        print("HandleAdClosing event received");
    }

    public void HandleAdClosed(object sender, EventArgs args)
    {
        bannerView.Destroy();
        RequestBanner();
        print("HandleAdClosed event received");
    }

    public void HandleAdLeftApplication(object sender, EventArgs args)
    {
        print("HandleAdLeftApplication event received");
    }

    #endregion

    #region Interstitial callback handlers

    public void HandleInterstitialLoaded(object sender, EventArgs args)
    {
        print("HandleInterstitialLoaded event received.");
    }

    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
    }

    public void HandleInterstitialOpened(object sender, EventArgs args)
    {
        print("HandleInterstitialOpened event received");
    }

    void HandleInterstitialClosing(object sender, EventArgs args)
    {
        print("HandleInterstitialClosing event received");
    }

    public void HandleInterstitialClosed(object sender, EventArgs args)
    {
        interstitial.Destroy();
        RequestInterstitial();
        print("HandleInterstitialClosed event received");
    }

    public void HandleInterstitialLeftApplication(object sender, EventArgs args)
    {
        print("HandleInterstitialLeftApplication event received");
    }

    #endregion
}

@NeverHopeless
@Gamedrill
@Dknighter2