我正在Unity3D制作2D游戏。当主角死亡时,出现带有“重启”(即Application.LoadLevel(“thisLevel”))和“转到主菜单”选项的菜单。但我需要插页式广告才能显示在菜单之前(字符模具=>广告出现)。我做的。但问题是:人物死亡,插页式广告出现,我关闭它,按菜单中的重启按钮,我让角色再次死亡,广告出现在1-2分钟后,这很奇怪。然后我按重启并让角色再次死亡,它会立即出现,应该如此。但是,如果我不等待第二次“死亡”后广告没有出现在第三次“死亡”之后,依此类推。这是我的代码:
using UnityEngine;
using System.Collections;
using UnityEngine.SocialPlatforms;
using GoogleMobileAds.Api;
public class AdBehaviourScript : MonoBehaviour {
private const string INTERSTITIAL_ID = "ca-app-pub-myNumers";
public InterstitialAd interstitial;
private bool showed;
void Start () {
DontDestroyOnLoad(transform.gameObject);
showed = false;
interstitial = new InterstitialAd(INTERSTITIAL_ID);
AdRequest request2 = new AdRequest.Builder().Build();
interstitial.LoadAd(request2);
}
void Update () {
}
public void showAd () {
if (interstitial.IsLoaded() && !showed) {
interstitial.Show();
showed = true;
}
}
public void destroyAd () {
interstitial.Destroy();
}
}
当角色死亡时,我会调用此脚本中的函数。如果您需要,这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.example.admobtest" android:versionName="1.0" android:versionCode="1">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<!-- Google Mobile Ads Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
<!-- meta-data tag for Google Play services -->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<meta-data android:name="android.app.lib_name" android:value="unity" />
</activity>
<activity android:name="com.unity3d.player.VideoPlayer" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigaton|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
</activity>
<!-- Google Mobile Ads Activity -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigati on|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
</manifest>
我的问题是什么?
答案 0 :(得分:0)
尝试隐藏广告而不是销毁广告
答案 1 :(得分:0)
在显示广告之前,您应该检查isInterstitialReady。 实际上,当显示广告时,admob插件会开始下载新广告。因为当你第二次调用广告时它还没有下载并在一秒后显示。您应该检查广告是否准备就绪,然后再发布广告。