0
votes

I know this question has been asked several times but i got stuck even though i have implemented and tried all the solutions. I follow this tutorial for interstitial ads showing:

https://developers.google.com/admob/unity/interstitial

My main goal is to show ad whenever user taps on "Restart" button for the game.

Here is my main ad manager class (which is linked with an game object):

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

public class AdManager : MonoBehaviour {

    public string interstitial_id;
    public string app_id;
    public InterstitialAd interstitial;

    // Use this for initialization
    void Start () {
        //MobileAds.Initialize(app_id);
        DontDestroyOnLoad(this);
        Prepare_Video();
        Debug.Log("Admob ilklendirildi: " + interstitial.ToString());
    }


    public void Show_Video()
    {
        Debug.Log("Reklam hazırlık durumu: " + interstitial.IsLoaded());
        if (interstitial.IsLoaded()) {
            Debug.Log("Reklam hazır, gösterilecek");
            interstitial.Show();
        }
        else
        {
            Prepare_Video();
            interstitial.Show();
        }
    }

    public void Destroy_Video()
    {
        if(interstitial != null)
        {
            interstitial.Destroy();
        }
    }

    public void Prepare_Video()
    {
        interstitial = new InterstitialAd(interstitial_id);
        AdRequest request = new AdRequest.Builder().Build();
        interstitial.LoadAd(request);
    }

}

I call the show method in restart action:

  public void RestartScene()
    {
        GameStatusText.gameObject.SetActive(false);
        RestartButton.gameObject.SetActive(false);
        MeterText.gameObject.SetActive(false);
        MeterTextTop.text = "";
        Time.timeScale = 1;
        TimeController.TimeLeft = 50f;
        FindObjectOfType<AdManager>().Show_Video();
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
3
Does it work if you comment out the LoadScene()-call?Fredrik Widerberg
I've tried but no luck :(metzelder
And you have verified that interstitial.IsLoaded() returns true?Fredrik Widerberg
Yes, i have verified.metzelder

3 Answers

1
votes

you need Initialize admob first

0
votes

Check what's going on with the scene that AdManager is assigned to, and if there is any changes to the scene, and do you have Google Ads unity asset installed in your game?

0
votes

I have reinstalled the admob plugin and followed the instructions from the beginning. It worked. It seems like my plugin package was damaged and some files were missing.