Hello. There is a problem with google AdMob. Test ads are shown in the editor (There are no errors in the editor), but real ads are not showing on my phone. Then I decided to use USB debugging and found out that the following error occurs:
"NullReferenceException: Object reference not set to an instance of an object.
at GoogleMobileAds.Api.MobileAds.Initialize (System.Action`1[T] initCompleteAction) [0x00000] in <00000000000000000000000000000000>:0
at Show_ads.Start () [0x00000] in <00000000000000000000000000000000>:0"
Here's my script:
using GoogleMobileAds.Api;
using System.Collections;
using System;
using UnityEngine.Scripting;
[assembly: Preserve]
public class Show_ads : MonoBehaviour
{
//ADS----------------------------
private RewardedAd rewardedAd;
private const string RewardedID = "id";
//ADS----------------------------
void Start()
{
MobileAds.Initialize(initStatus => { });
LoadRewardedAD();
}
private void LoadRewardedAD()
{
//load-ad
rewardedAd = new RewardedAd(RewardedID);
AdRequest adRequest = new AdRequest.Builder().Build();
rewardedAd.LoadAd(adRequest);
rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
}
//Called from another script
public void ShowRewardedAD()
{
if (rewardedAd.IsLoaded())
{
rewardedAd.Show();
}
}
public void HandleUserEarnedReward(object sender, Reward args)
{
if (Reward_type == 0)
{
//gem
}
else if (Reward_type == 1)
{
//coin
}
else if (Reward_type == 2)
{
//Respawn
}
}
private IEnumerator WaitAD()
{
yield return new WaitForSeconds(3);
LoadRewardedAD();
}
}
Who can help?
↧