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("GameManager").GetComponent<GameManager>();
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?
GameObject.Find("GameManager").GetComponent<GameManager>()
, did you mean to just writeFindObjectOfType<GameManager>()
? – DMGregory Jun 23 '20 at 13:10