簡體   English   中英

Unity獎勵了視頻廣告

[英]Unity rewarded video ads

一旦用戶觀看了獎勵的視頻廣告,我想給予用戶3個額外的生命,並讓用戶從玩家死亡的地方繼續游戲以及相同的分數。

我已經能夠添加額外的生命代碼,但我無法獲得相同的分數。

這是分數腳本:

public int playerScore = 0; 

if (!isDead && collision.tag == "ScoreChecker") {
        gameManager.AddToScore();
    }

public void AddToScore()
{
    playerScore++;
    if (playerScore > PlayerPrefs.GetInt("HighScore",0))
    {
        PlayerPrefs.SetInt("HighScore", playerScore);
        Debug.Log("Highscore");
    }

    Debug.Log("player score" + playerScore);
}

這是額外的生命獎勵劇本:

public void ReceiveReward()
 {
    totalLives = 3;
    UIManager.instance.UpdateLivesIcons();        
    UIManager.instance.RewardPanel.SetActive(false);
 }

我已經能夠獎勵額外的生命,但不知道如何讓玩家在玩家死亡時繼續使用相同的分數。

好吧,據我了解你的問題,你在玩家死亡時難以保存得分,然后又恢復了你想要繼續。

private savedScore = 0;
//Call this function when your player dies.
public void SaveScoreBeforeDeath()
{
    savedScore = playerScore
}
//get your saved score and assign it.
public void ReceiveReward()
 {
    totalLives = 3;
    playerScore = savedScore;
    UIManager.instance.UpdateLivesIcons();        
    UIManager.instance.RewardPanel.SetActive(false);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM