NullReferenceException: Object reference not set to an instance of an object. Admob problem.
Hi i have a problem with admob, i dont know what to do.
NullReferenceException: Object reference not set to an instance of an object Colision.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/Scripts/Colision.cs:28)
this is my ads script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GoogleMobileAds.Api;
using UnityEngine.UI;
public class admanager : MonoBehaviour
{
public Text adStatus;
public static admanager instance;
private string appID = "ca-app-pub-3940256099942544~3347511713";
private InterstitialAd fullScreenAd;
private string fullScreenAdID = "ca-app-pub-3940256099942544/1033173712";
[Obsolete]
private void Start()
{
MobileAds.Initialize(appID);
//MobileAds.Initialize(initStatus => { });
}
public void RequestFullScreenAd()
{
this.fullScreenAd = new InterstitialAd(fullScreenAdID);
// Called when an ad request has successfully loaded.
this.fullScreenAd.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
this.fullScreenAd.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is shown.
this.fullScreenAd.OnAdOpening += HandleOnAdOpened;
// Called when the ad is closed.
this.fullScreenAd.OnAdClosed += HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
this.fullScreenAd.OnAdLeavingApplication += HandleOnAdLeavingApplication;
AdRequest request = new AdRequest.Builder().Build();
this.fullScreenAd.LoadAd(request);
}
public void ShowFullScreenAd()
{
if (this.fullScreenAd.IsLoaded())
{
this.fullScreenAd.Show();
}
}
//For Event adn delegate
public void HandleOnAdLoaded(object sender, EventArgs args)
{
adStatus.text = "Ad loaded";
if(this.fullScreenAd.IsLoaded())
{
this.fullScreenAd.Show();
}
}
public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
adStatus.text = "Ad not loaded";
}
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");
}
}
And this is my "Show up" ads script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using GoogleMobileAds.Api;
public class Colision : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "Player")
{
admanager.instance.ShowFullScreenAd();
SceneManager.LoadScene("GameOver");
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Admob interstitial ads - Deleted a jar file 0 Answers
Google analytics 1 Answer
How to display ads every 5 mins ? 1 Answer
AdMob Reward Video for Unity 1 Answer