0

I'm implementing reward based video ads in my game. There are two functions that provide the reward. One is a ReceiveLife() function where once the player dies, if they click on the revive button the game restarts and the score is set to score before the player dies instead of 0. The other function is ReceivePoints(), where if the player clicks on the add points button, they are rewarded with 100 extra points. Here are the functions in the game manager script:

 public void ReceiveLife()
   {        
     savedScore = (int)playerScore;        
     SceneManager.LoadScene(1); 
   }

public void ReceivePoints() { playerScore+=100; gameOverPanel.gameOverScoreText.text = "Score: " + ((int)playerScore).ToString(); }

Here is the unity ads manager script:

 public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
  {        
    if (showResult == ShowResult.Finished)
    {
        gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
        gameManager.ReceiveLife();
    }
if (showResult == ShowResult.Finished)
{
    gameManager = GameObject.Find(&quot;GameManager&quot;).GetComponent&lt;GameManager&gt;();
    gameManager.ReceivePoints();
}       

}

Once they watch the ad successfully, both the functions are being called. If the player clicks on the ReceiveLife(), he should only get one extra life and not the additional 100 points and vice-versa.

I'm not sure how to call each function separately. Do I have to create two separate admanagers in order to call these functions or is there a better method?

single arrow games
  • 167
  • 1
  • 2
  • 12
  • Where do you implement your revive button and your add points button? – DMGregory Jun 23 '20 at 12:16
  • Also, instead of the clunky GameObject.Find("GameManager").GetComponent<GameManager>(), did you mean to just write FindObjectOfType<GameManager>()? – DMGregory Jun 23 '20 at 13:10
  • @DMGregory , both the buttons are shown once the player dies....regarding the 2nd query, I was just following some tutorials on youtube. I will incorporate the shorter code that you provided. – single arrow games Jun 23 '20 at 16:13
  • Where is your code that handles those two buttons? – DMGregory Jun 23 '20 at 16:17
  • its in the game manager script....here is to link to it...you had helped me with it yesterday..https://gamedev.stackexchange.com/questions/183762/persisting-score-when-restarting-level-after-a-rewarded-video-ad/183770#183770 – single arrow games Jun 23 '20 at 16:23
  • If it's related to this question, it belongs in this question. Please ensure your question contains a Minimal Complete Verifiable Example, so a user can see everything they need to reproduce the problem in one place. – DMGregory Jun 23 '20 at 16:30
  • oh.....sorry about that....I will update that question..... – single arrow games Jun 23 '20 at 17:11

0 Answers0