我在 Unity 中有 InterstitialAds 的这段代码,我想每次都开始这个全屏广告,当关卡关闭并且新关卡开始时,所以我使用 OnDestroy 函数,但是什么时候必须调用interstitial.destroy();
?之间:代码是否适合游戏流畅运行?感谢所有回答,对不起我的英语:)
public class GoogleAdsScript : MonoBehaviour
{
bool isLoaded = false;
private InterstitialAd interstitial;
private BannerView bannerView;
void Start()
{
RequestInterstitial();
//RequestBanner();
}
void OnDestroy()
{
if (interstitial.IsLoaded() && isLoaded == false)
{
interstitial.Show();
isLoaded = true;
}
}
private void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
private void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
}