Hello,
So my game has very short levels, could be from 1 sec to 30 sec and my ads get reloaded everytime I reload the scene.
What I want to do is when you die I show an ad, but do not want to make a Adrequest every 5 seconds, but rather just show it.
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleAdmob : MonoBehaviour
{
private BannerView bannerView;
private static string outputMessage = “”;
private static bool created = false;
public static string OutputMessage
{
set { outputMessage = value; }
}
void Awake(){
if(!created){
DontDestroyOnLoad(gameObject);
created = true;
} else {
Destroy(gameObject);
}
}
void Start(){
RequestBanner ();
bannerView.Hide ();
}
public void RequestBanner()
{
#if UNITY_EDITOR
string adUnitId = “unused”;
#elif UNITY_ANDROID
string adUnitId = “xxx”;
#elif UNITY_IPHONE
string adUnitId = “xxx”;
#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.AdLoaded += HandleAdLoaded;
bannerView.AdFailedToLoad += HandleAdFailedToLoad;
bannerView.AdOpened += HandleAdOpened;
bannerView.AdClosing += HandleAdClosing;
bannerView.AdClosed += HandleAdClosed;
bannerView.AdLeftApplication += HandleAdLeftApplication;
// Load a banner ad.
bannerView.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))
//.AddExtra(“color_bg”, “9B30FF”)
.Build();
}
}
But whenever the scene is reloaded, i lose the reference to the bannerView, and I can no longer cal:
bannerView.Show();
bannerView.Hide();
How can I keep the reference on reload?