0

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.

Le Pain
  • 75
  • 9
adi pat
  • 11
  • 7
  • 1
    What about the death script? Does the game continue playing correctly just the score resets to 0 or what happens? – MomasVII Jun 12 '19 at 06:19
  • @ThomasByy, once the player dies, the score resets to 0. This works as required.....its just the I was not able to get the score once the player has watched a video add...I will try the solution given by syed... – adi pat Jun 13 '19 at 04:37

1 Answers1

0

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);
 }
Syed Munim Raza
  • 195
  • 2
  • 11