[ad_1]
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
2k times
I have create a Unity game, 1st I add an AdMob interstitial ads script on game object then try on my main camera when I test in my mobile before publishing. It has worked like real time ads and mistakenly clicked it and earn 0.3 so I create new ad unit placed it on my game then published my game. But the ads are not showing in real time. No error was found in AdMob but 147 ad requests are shown in AdMob and ads are not visible when my game 1st scene opens.
Here is my interstitial ads script code:
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdmobScript : MonoBehaviour
{
private InterstitialAd interstitial;
private void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3129337025883034/9036322***";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an interstitial.
this.interstitial = new InterstitialAd(adUnitId);
// Load an interstitial ad.
this.interstitial.LoadAd(this.CreateAdRequest());
}
// Returns an ad request
private AdRequest CreateAdRequest()
{
return new AdRequest.Builder().Build();
}
private void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
public void Start()
{
RequestInterstitial();
}
void Gameover()
{
if(interstitial.isloaded){
ShowInterstitial();
}
}
}
\$\endgroup\$
1
The ad need a Build request function. Execute the below code and run on the testing device. if you got test ads then surely it will open in play store version also. Then update the new build in play store.
private void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3129337025883034/9036322***";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an interstitial.
this.interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
}
The ad calling method must be like this
private void GameOver()
{
if (this.interstitial.IsLoaded()) {
this.interstitial.Show();
}else{
RequestInterstial();
}
}
\$\endgroup\$
2
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged .
lang-cs
[ad_2]