我正在尝试整合广告,但问题是没有显示奖励广告。但是,插页式广告确实有效。场景等待 2.3 秒并显示插页式广告,但不显示奖励广告,即使在日志中显示“SHOW AD XXX”。
这是游戏脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gamescript: MonoBehaviour {
public static bool isGameover;
// Use this for initialization
void Start() {
isGameover = false;
Invoke("GameOver", 2);
}
// Update is called once per frame
void Update() {
}
void GameOver() {
isGameover = true;
Debug.Log("Game Over");
}
}
这是我的奖励广告脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
public class Newreward: MonoBehaviour {
private RewardBasedVideoAd rewardBasedVideo;
bool hasShownAdOneTime;
// Use this for initialization
void Start() {
rewardBasedVideo = RewardBasedVideoAd.Instance;
// Called when the user should be rewarded for watching a video.
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
// Called when the ad is closed.
rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
LoadRewardBasedAd();
}
// Update is called once per frame
void Update() {
if (Gamescript.isGameover) {
if (!hasShownAdOneTime) {
hasShownAdOneTime = true;
Invoke("ShowRewardBasedAd", 3);
}
}
}
public void LoadRewardBasedAd() {
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
string adUnitId = "unexpected_platform";
#endif
rewardBasedVideo.LoadAd(new AdRequest.Builder().Build(), adUnitId);
}
public void ShowRewardBasedAd() {
if (rewardBasedVideo.IsLoaded()) {
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
rewardBasedVideo.Show();
Debug.Log("SHOW AD XXX");
} else {
MonoBehaviour.print("Dude no ad");
}
}
public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args) {
this.LoadRewardBasedAd();
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args) {
string type = args.Type;
double amount = args.Amount;
MonoBehaviour.print("HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type);
}
}
任何帮助,将不胜感激