广告在编辑器中有效,但在Android中无效

问题描述

我正在尝试在我的游戏中使用广告。他们可以在Unity中正常工作,但不能在Android中工作。由于我使用的是unity 2018.4.25f1个人版,因此它支持的旧版unity货币化资产。也许是个问题,但这是我的Rewarded Video CSharp文件代码

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

[RequireComponent(typeof(Button))]
public class RewardedVideo : MonoBehavIoUr,IUnityAdsListener
{

#if UNITY_IOS
    private string gameId = "3853032";
#elif UNITY_ANDROID
    private string gameId = "3853033";
#endif

    [Serializefield]Button myButton;
    [Serializefield]GameObject errorMessage;
    public string myPlacementId = "rewardedVideo";

    void Start()
    {

        // Map the ShowRewardedVideo function to the button’s click listener:
        if (myButton)
            myButton.onClick.AddListener(ShowRewardedVideo);

        // Initialize the Ads listener and service:
        Advertisement.AddListener(this);
        Advertisement.Initialize(gameId,true);
    }
    public void okError()
    {
        errorMessage.SetActive(false);
    }
    // Implement a function for showing a rewarded video ad:
    public void ShowRewardedVideo()
    {
        if(Advertisement.IsReady() == true)
            Advertisement.Show(myPlacementId);
        else
            errorMessage.SetActive(true);
    }

    // Implement IUnityAdsListener interface methods:
    public void OnUnityAdsReady(string placementId)
    {
        // If the ready Placement is rewarded,activate the button: 
        if (placementId == myPlacementId)
        {
            // myButton.interactable = true;
        }
    }

    public void OnUnityAdsDidFinish(string placementId,ShowResult showResult)
    {
        // Define conditional logic for each ad completion status:
        if (showResult == ShowResult.Finished)
        {
            int levels = PlayerPrefs.GetInt("unlockedLevel",1);
            if(levels != 5)
            {
                PlayerPrefs.SetInt("unlockedLevel",levels+1);
            }
        }
        else if (showResult == ShowResult.Skipped)
        {
            // Do not reward the user for skipping the ad.
        }
        else if (showResult == ShowResult.Failed)
        {
            Debug.LogError("The ad did not finish due to an error");
        }
    }

    public void OnUnityAdsDidError(string message)
    {
        // Log the error.
    }

    public void OnUnityAdsDidStart(string placementId)
    {
        // Optional actions to take when the end-users triggers an ad.
    }
}

从资产商店而不是从程序包管理器下载的资产。我看到Unity帮助,统一论坛,stackoverflow,但是没有任何解决我的问题的方法 有什么建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)