我使用的是來自admob的激勵視頻廣告。廣告在玩家死亡時被調用,並詢問他們是否想要觀看要復活的廣告。我試圖檢查廣告是否完成,以便我可以獎勵玩家。如何檢查廣告是否已在Unity中完成
void Update()
{
if(isCalled == true){
string adUnitId = "ca-app-pub-5920324855307233/4458481507";
RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
showAd(rewardBasedVideo);
}
}
public void showAd(RewardBasedVideoAd rewardBasedVideo)
{
if (rewardBasedVideo.IsLoaded())
{
//Subscribe to Ad event
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
rewardBasedVideo.Show();
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
string type = args.Type;
double amount = args.Amount;
//Reawrd User here
print("User rewarded with: " + amount.ToString() + " " + type);
isCalled = false;
managerScript.revival();
managerScript.Loading.SetActive(false);
}
第一次通告了對場景中的方法復興被調用,加載屏幕觀看被關閉,一切正常,之後,當廣告再次它不工作的注視下,「HandleRewardBasedVideoRewarded」方法沒有被調用,一個新的廣告只是彈出來觀看一遍又一遍。我如何解決這個問題,因爲當廣告第二次完成時,遊戲不會調用「HandleRewardBasedVideoRewarded」方法。所以方法的復甦被調用,並且加載屏幕像第一次打開遊戲時一樣關閉。 注意:即使場景重新啓動(而不是整個遊戲),問題仍然會發生。
更新: 我已編輯腳本到您的解決方案,但問題仍然存在。 Whay不是在工作嗎? 以下是完整的腳本:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using UnityEngine.Advertisements;
public class GameAdvertising : MonoBehaviour {
public bool isCalled;
public GameObject Manager;
GameManager managerScript;
string adUnitId = "ca-app-pub-5920324855307233/4458481507";
RewardBasedVideoAd rewardBasedVideo = null;
void Start() {
managerScript = gameObject.GetComponent<GameManager>();
isCalled = false;
//Subscribe to Ad event once
rewardBasedVideo = RewardBasedVideoAd.Instance;
//Subscribe to Ad event once
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
public void adButton()
{
isCalled = true;
}
void Update()
{
if(isCalled == true){
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
showAd();
}
}
public void showAd()
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
string type = args.Type;
double amount = args.Amount;
//Reawrd User here
print("User rewarded with: " + amount.ToString() + " " + type);
isCalled = false;
managerScript.revival();
managerScript.Loading.SetActive(false);
}
}
我不能適合我的回覆在這裏所以我更新問題 – Physix
@Physix我修改了我的答案與一堆的打印語句。請複製新代碼,運行它,然後在程序第二次運行時使用打印語句中的日誌更新您的問題。我可以用它來確定發生了什麼壞事。 – Programmer
我只是測試我的應用程序構建並通過USB直接運行到我的三星A5,我如何登錄(道歉爲初學者問題)。 – Physix