Unity Admob Interstitial Ads Not Showing - unity3d

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);
}

you need Initialize admob first

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?

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.

Related

unity ads not showing up

i followed the official unity tutorial on how to put bannner ads on my game, i set everything up in the unity dashboard, and in the editor i see a rectangle that says the ad should be there, but when i build the game nothing shows up, here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class bannerad : MonoBehaviour
{
bool testMode = false;
public string gameId = "******" (my game id is here i just dot want to share it);
// Start is called before the first frame update
IEnumerator Start()
{
Advertisement.Initialize(gameId, testMode);
while (!Advertisement.IsReady("Lost_Ad"))
{
yield return null;
}
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Show("Lost_Ad");
}
}
anyone knows what is the solution?
Are you ever calling this function? If you just replaced the Start function with this IEnumerator it will not get called unless you call it.
private void Start()
{
Advertisement.Initialize(gameId, testMode);
StartCoroutine(StartAds());
}
private IEnumerator StartAds()
{
// your code here
}

How to Show Admob Interstitials on Counted Click?

I am trying to something like this:
if button clicked for 4 times, I could show Interstitial?
However i couldn't make it happen.
Created a game object.
Attached script to that object.
Created a restart button.
Implemented this object on that button with onclick-runtime only etc.
Now every time user clicks restart button, interstitial ads show itself. but of course as you might know, it is very annoying.
I dont know how to count how many times users press the restart button and for example show the ads every 3 or 4 times if user press the button.
Thank you.
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdScript : MonoBehaviour
{
InterstitialAd interstitial;
public string InterstitialId;
// Use this for initialization
void Start()
{
//Request Ads
//RequestBanner();
RequestInterstitial();
}
public void showInterstitialAd()
{
//Show Ad
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
private void RequestInterstitial()
{
string adUnitId = InterstitialId;
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
}
I can give you idea ,you can use time class to know last showed ad or use variable saying like every 4 game show ad on restart button click.
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdScript : MonoBehaviou
{
int counter =0;
InterstitialAd interstitial;
public string InterstitialId;
// Use this for initialization
void Start()
{
//Request Ads
//RequestBanner();
RequestInterstitial();
}
public void showInterstitialAd()
{
counter ++;
if(counter%4==0)
{
//Show Ad
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
private void RequestInterstitial()
{
string adUnitId = InterstitialId;
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
}

Unity2D: Admob - Reward system

I'm having problems with my code, you see I imported Google Admob into my project. I integrated the reward system into my AdManager script, using Github's Plugin Wiki and Documentation. However (in my AdManager script) my rewarding the user function isn't really working, I have a static int from another script that gives my player a boomerang when they pick it up in the game, buy it or receive from watching a video. Below is my AdManager script:
public class AdManager : MonoBehaviour
{
public static AdManager Instance { set; get; }
public string bannerId;
public string videoId;
private void Start()
{
Instance = this;
DontDestroyOnLoad(gameObject);
#if UNITY_EDITOR
#elif UNITY_ANDROID
Admob.Instance().initAdmob(bannerId, videoId);
Admob.Instance().setTesting(true);
Admob.Instance().loadInterstitial();
Admob.Instance().rewardedVideoEventHandler += onRewardedVideoEvent;
#endif
}
public void Reward()
{
Admob ad = Admob.Instance();
if (ad.isRewardedVideoReady())
{
ad.showRewardedVideo();
}
else
{
ad.loadRewardedVideo("ca-app-pub-2099082167446861/xxxxxxxxxx");
}
}
void onRewardedVideoEvent(string eventName, string msg)
{
WeaponScript.boomerang += 1;
Debug.Log("Well Done! You have been rewarded one Boomerang!");
Debug.Log("handler onRewardedVideoEvent---" + eventName + " " + msg);
}
}
My problem: I built the game and tried it out, watched a video got a reward (boomerang), but when I did it again (watch another reward video) I didn't get another reward (boomerang). Not sure if I'm doing it wrong. Please can anyone help me with my problem. Thank you!

showing admob interstitial every x play unity

I am trying to make my interstitial admob ad appear when a user enters the map for the third time.
My code is:
using UnityEngine;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class interstitial_ad : MonoBehaviour {
private InterstitialAd interstitial;
void Start()
{
interstitial = new InterstitialAd ("ca-app-pub-xxx");
interstitial.LoadAd (new AdRequest.Builder ().Build ());
}
void Update()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
It shows the ad every time I enter the map, so I tried to add:
playCount++;
if (playCount % 3 == 0) {
but that did not work for me, probably because of the void Update() part. Do you have any ideas/hints how to make it work?

Facebook/Unity SDK, Web build login not working

I have tried changing the InteractiveConsole script that comes with the Facebook/Unity SDK to simply make it use Login via the facebook account, as a start. Before building for the web it works fine (inside Unity), I get the access token window and I can see my own facebook ID in the console afterwards. But when I build it for the web and click on the same login button nothing happens. I have no idea why.
Here's my code:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public sealed class InteractiveConsole : MonoBehaviour
{
#region FB.Init() example
private void CallFBInit()
{
FB.Init(OnInitComplete, OnHideUnity);
}
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
CallFBLogin ();
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
#endregion
#region FB.Login() example
private void CallFBLogin()
{
FB.Login("email,publish_actions", LoginCallback);
}
void LoginCallback(FBResult result)
{
if (!FB.IsLoggedIn)
{
Debug.Log ("User cancelled login.");
}
else
{
Debug.Log ("User ID: " + FB.UserId);
if(FB.IsLoggedIn)
Application.LoadLevel("main");
}
}
#endregion
void OnGUI()
{
if (Button("Login"))
{
CallFBInit();
}
}
private bool Button(string label)
{
return GUILayout.Button(
label
);
}
}
I'm sure I'm missing something. Can someone tell me what's wrong?
There's more I'd like to understand, is the Access Token Unity window there to replace the usual Login/Asking for Permissions window in the final game (as seen in basically every app used on facebook)? If not, how do I get the proper Login window?
I've the same problem, however I did find a way to make it work. If you directly link to the Unity Binary URL instead of linking to a secure Canvas page you should be able to login. However I don't know how to change the looks of the page around the unity3D application.