我目前正在开发虚拟宠物上的Android游戏,最近我已将Unity Ads更新到版本3.4.1,现在控制台显示错误(在脚本之后)。 脚本:
using UnityEngine.UI;
using UnityEngine.Advertisements;
[RequireComponent(typeof(Button))]
public class RecoverAdsButton : MonoBehaviour, IUnityAdsListener
{
private string gameId = "3405140";
Button recoverButton;
public string myPlacementId = "rewardedVideo";
void Start()
{
recoverButton = GetComponent<Button>();
// Set interactivity to be dependent on the Placement’s status:
recoverButton.interactable = Advertisement.IsReady(myPlacementId);
// Map the ShowRewardedVideo function to the button’s click listener:
if (recoverButton) recoverButton.onClick.AddListener(ShowRewardedVideo);
// Initialize the Ads listener and service:
Advertisement.AddListener(this);
Advertisement.Initialize(gameId, false);
}
// Implement a function for showing a rewarded video ad:
void ShowRewardedVideo()
{
Advertisement.Show(myPlacementId);
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsReady(string placementId)
{
// If the ready Placement is rewarded, activate the button:
if (placementId == myPlacementId)
{
recoverButton.interactable = true;
}
}
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.
PlayerPrefs.SetInt("_happiness", 100);
PlayerPrefs.SetInt("_hunger", 100);
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("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网站获取了此脚本。
我需要知道如何解决此错误:The type 'IUnityLifecycleManager' exists in both 'UnityEngine.Advertisements.Editor, Version=3.4.1.0, Culture=neutral, PublicKeyToken=null' and 'UnityEngine.Advertisements, Version=3.4.1.0, Culture=neutral, PublicKeyToken=null'
我真的不知道该怎么办,我尝试更改IUnityAdsListener或更改其位置,但也无济于事。在不完全更改脚本的情况下如何解决此问题?