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.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.