[英]Unity rewarded video ads
Once the user has finished watching the rewarded video ad, I want to give the user 3 additional lives and let the user continue the game from where the player died along with the same score. 一旦用户观看了奖励的视频广告,我想给予用户3个额外的生命,并让用户从玩家死亡的地方继续游戏以及相同的分数。
I have been able to add the extra lives code but am not able to get the same score. 我已经能够添加额外的生命代码,但我无法获得相同的分数。
This is the score script: 这是分数脚本:
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);
}
This is the extra lives reward script: 这是额外的生命奖励剧本:
public void ReceiveReward()
{
totalLives = 3;
UIManager.instance.UpdateLivesIcons();
UIManager.instance.RewardPanel.SetActive(false);
}
I have been able to reward the extra lives, but not sure how to let the user continue with the same score when the player died. 我已经能够奖励额外的生命,但不知道如何让玩家在玩家死亡时继续使用相同的分数。
Well as far as I have understood your question you are facing difficulty in saving score at the point your player died and then revived back you want to continue. 好吧,据我了解你的问题,你在玩家死亡时难以保存得分,然后又恢复了你想要继续。
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.