using System; using UnityEngine; using UnityEngine.UI; using GoogleMobileAds.Api; public class adsScript : MonoBehaviour { public static adsScript instance {get; private set;} private void Awake() { if (instance == null) {instance = this; DontDestroyOnLoad(this.gameObject);} else { Destroy(this.gameObject); } } private RewardedAd rewardedAd; public void RequestReward() { string adUnitId = "ca-app-pub-3940256099942544/5224354917"; this.rewardedAd = new RewardedAd(adUnitId); this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded; this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad; this.rewardedAd.OnAdOpening += HandleRewardedAdOpening; this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow; this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward; this.rewardedAd.OnAdClosed += HandleRewardedAdClosed; AdRequest request = new AdRequest.Builder().Build(); this.rewardedAd.LoadAd(request); } public GameManager gameManager; public void HandleRewardedAdLoaded(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardedAdLoaded event received"); } public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args) { MonoBehaviour.print( "HandleRewardedAdFailedToLoad event received with message: " + args.Message); this.reqRewardedAdVideo = true; } public void HandleRewardedAdOpening(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardedAdOpening event received"); } public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args) { MonoBehaviour.print( "HandleRewardedAdFailedToShow event received with message: " + args.Message); } public void HandleRewardedAdClosed(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardedAdClosed event received"); this.reqRewardedAdVideo = true; OnDestroy(); } public void HandleUserEarnedReward(object sender, Reward args) { gameManager.gameOverCanvas.SetActive(false); gameManager.ShowReward(); } public void ShowRewardVideo() { if (this.rewardedAd.IsLoaded()) { this.rewardedAd.Show(); } else { Debug.Log("Reward video is not ready yet"); } } public void Start() { MobileAds.Initialize(initStatus => { }); this.RequestBanner(); this.RequestInterstitial(); this.RequestReward(); } private bool reqRewardedAdVideo = true; public void Update() { if (reqRewardedAdVideo) { this.RequestReward(); reqRewardedAdVideo = false; } } public void OnDestroy() { this.rewardedAd.OnAdLoaded -= HandleRewardedAdLoaded; this.rewardedAd.OnAdFailedToLoad -= HandleRewardedAdFailedToLoad; this.rewardedAd.OnAdOpening -= HandleRewardedAdOpening; this.rewardedAd.OnAdFailedToShow -= HandleRewardedAdFailedToShow; this.rewardedAd.OnUserEarnedReward -= HandleUserEarnedReward; this.rewardedAd.OnAdClosed -= HandleRewardedAdClosed; } }
Hi Darius,
Thank you for expanding on your concerns.
I suspect that the action of restarting your game level may be incorrectly tampering with your ads script (especially with the singleton vs OnDestroy() interaction), although I'm afraid that I am unable to pinpoint the main cause of the issue just yet. Just to double check the implementation: is your game manager script also a singleton that is still properly referenced by your ads script after a level restart?
With all this in mind, could you kindly provide the details below (via a private email to mobileads...@gmail.com) so that I can further investigate the issue?
You may zip the entire Unity project (excluding the Library and Temp folders) in order to reduce its size, then send it to me via a shareable link from your Google Drive (or on any other file-sharing site that you prefer). Don't forget to send the shareable link via a private email to mobileads...@gmail.com.
Regards,
Ziv Yves Sanchez
Mobile Ads SDK Team