统一单击重新启动按钮后如何显示广告然后重新启动场景?
Posted
技术标签:
【中文标题】统一单击重新启动按钮后如何显示广告然后重新启动场景?【英文标题】:how to show ads and then restart scene after clicking restart button in unity? 【发布时间】:2022-01-15 02:23:20 【问题描述】:我是 Unity 新手,需要帮助,以下脚本是我的广告管理器脚本。
我有一个重启按钮,在点击事件时,我想展示一个广告然后开始一个场景,但是当我点击重启按钮时,它会显示一个广告几毫秒然后场景开始......
如何显示完全然后加载场景?谢谢。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;
using UnityEngine.SceneManagement;
public class ADSmanager : MonoBehaviour
private InterstitialAd interstitial_Ad;
private RewardedAd rewardedAd;
private string interstitial_Ad_ID;
private string rewardedAd_ID;
void Start ()
interstitial_Ad_ID = "ca-app-pub-3940256099942544/1033173712";
rewardedAd_ID = "ca-app-pub-3940256099942544/5224354917";
MobileAds.Initialize (initStatus => );
RequestInterstitial ();
RequestRewardedVideo ();
private void RequestInterstitial ()
interstitial_Ad = new InterstitialAd (interstitial_Ad_ID);
interstitial_Ad.OnAdLoaded += HandleOnAdLoaded;
AdRequest request = new AdRequest.Builder ().Build ();
interstitial_Ad.LoadAd (request);
private void RequestRewardedVideo ()
rewardedAd = new RewardedAd (rewardedAd_ID);
rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
rewardedAd.OnAdClosed += HandleRewardedAdClosed;
rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
AdRequest request = new AdRequest.Builder ().Build ();
rewardedAd.LoadAd (request);
public void ShowInterstitial ()
if (interstitial_Ad.IsLoaded ())
interstitial_Ad.Show ();
RequestInterstitial ();
// else
// Savers.Score=0;
// Savers.died=false;
// SceneManager.LoadScene(1);
// Time.timeScale=1;
//
//Time.timeScale=1;
public void ShowRewardedVideo ()
if (rewardedAd.IsLoaded ())
rewardedAd.Show ();
public void HandleOnAdClosed(object sender, EventArgs args)
public void HandleOnAdLoaded (object sender, EventArgs args)
public void HandleRewardedAdFailedToShow (object sender, AdErrorEventArgs args)
RequestRewardedVideo ();
public void HandleRewardedAdClosed (object sender, EventArgs args)
RequestRewardedVideo ();
public void HandleUserEarnedReward (object sender, Reward args)
RequestRewardedVideo ();
`
【问题讨论】:
【参考方案1】:在这个方法中加载场景。而在编辑器中,关闭按钮将处理此方法。与在编辑器中一样,不会显示实际的广告。
public void HandleUserEarnedReward (object sender, Reward args)
RequestRewardedVideo ();
sceneManager.LoadScene(sceneIndex);
【讨论】:
和插页式广告?? 插页式广告,public void ShowInterstitial () if (interstitial_Ad.IsLoaded ()) interstitial_Ad.Show (); RequestInterstitial ();sceneManager.LoadScene(sceneIndex);
当我按照你的建议调用它时。它会显示广告并自动移动到下一个场景而不关闭广告
是的。这就是编辑器中将发生的事情。它将在 android 构建中正常工作。
非常感谢以上是关于统一单击重新启动按钮后如何显示广告然后重新启动场景?的主要内容,如果未能解决你的问题,请参考以下文章
重新启动后,按钮单击时,小组件onUpdate未设置pendingIntent