如何为用户观看Unity Ads带来额外的生命?

时间:2015-10-24 20:09:49

标签: c# unity3d

我希望在Unity的小游戏制作中为用户观看Unity Ads提供额外的生命。但我不知道该怎么做。

要展示我使用的广告:

void Awake()
{
    Advertisement.Initialize (gameID, true);
}

public void ShowAd()
{
#if UNITY_EDITOR
    StartCoroutine(WaitForAd ());
#endif

    if (Advertisement.IsReady ())
        Advertisement.Show ();
}

IEnumerator WaitForAd()
{
    float currentTimeScale = Time.timeScale;
    Time.timeScale = 0f;
    yield return null;

    while (Advertisement.isShowing)
        yield return null;

    Time.timeScale = currentTimeScale = 0f;

我使用例如

计算另一个脚本中的生命
if (other.gameObject.CompareTag ("Meteor")) {
    other.gameObject.SetActive (false);
    count_lives = count_lives - 1;
    SetLivesText ();
}

但是团结广告的脚本中的count_lives = count_lives +1不起作用,顺便说一句,我使用UnityEngine.UI来显示生命的数量。也许它可以与用于开始展示广告的按钮连接?

1 个答案:

答案 0 :(得分:0)

如果他在观看广告时每次玩游戏,是否应该让玩家获得更多生命? 如果是这样我认为你应该尝试使用播放器首选项。

in youre“void awake(){}”你应该添加以下内容:

PlayerPrefs.GetInt("AdLives");
PlayerPrefs.SetInt("AdLives", 1);

然后在你的脚本中有生命变量你应该添加:

void Start (){

   if(PlayerPrefs.GetInt("Adlives")==1){
      //set the variable that countes the lives to the amount you want for example:
     lives=5;
   }
}