广告测试在编辑器上运行,但不是在构建到 android 之后。在编辑器模式下,测试像这样运行
如您所见,测试模式还可以在这些服务和 Unity 的仪表板上启用测试模式。我正在使用 v 3.4.6 的资产商店中的 Unity 货币化。这是我的脚本:
using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;
public class UnityAds : MonoBehaviour, IUnityAdsListener
{
[Header("Ads Stuff")]
public string Google_ID = "******";
bool testMode = true;
public string myPlacement = "rewardedVideo";
void Awake()
{
Advertisement.AddListener(this);
Advertisement.Initialize(Google_ID, testMode);
}
// calling when player Death
public void DisplayVideoAds()
{
StartCoroutine(ShowRewardedVideo());
Debug.Log("Test Mode activate");
}
#if UNITY_ANDROID|| UNITY_IOS
public IEnumerator ShowRewardedVideo()
{
// Check if UnityAds ready before calling Show method:
while (!Advertisement.IsReady())
{
yield return new WaitForSeconds(1);
}
Advertisement.Show();
}
#endif
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
// Reward the user for watching the ad to completion.
Debug.LogWarning("You got A 2x Reward !!");
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
Debug.LogWarning("You got A Min Reward !!");
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("The ad did not finish due to an error.");
}
}
public void OnUnityAdsReady(string placementId)
{
// If the ready Placement is rewarded, show the ad:
if (placementId == myPlacement)
{
// Optional actions to take when the placement becomes ready(For example, enable the rewarded ads button)
}
}
public void OnUnityAdsDidError(string message)
{
// Log the error.
}
public void OnUnityAdsDidStart(string placementId)
{
// Optional actions to take when the end-users triggers an ad.
}
// When the object that subscribes to ad events is destroyed, remove the listener:
public void OnDestroy()
{
Advertisement.RemoveListener(this);
}
}
我不知道发生了什么,但在 Debug 上没有显示错误:
最后我有这样的警告
Please consider upgrading to the Packman Distribution of the Unity Ads SDK. The Asset Store distribution will no longer be supported after Unity 2018.3
那是因为无法在android上运行吗?我是否必须先在 google play store 上发布测试版应用程序才能进行测试?