public class AdManager : MonoBehaviour {
GameManager gameManager;
LivesManager lifeManager;
private void Awake () {
if (!Advertisement.isInitialized) {
Advertisement.Initialize("1513938", true); //// 1st parameter is String and 2nd is boolean
Debug.Log("Initialized manually");
}
}
private void Start () {
gameManager = FindObjectOfType<GameManager>();
lifeManager = FindObjectOfType<LivesManager>();
}
public void ShowRewardedAd () {
Debug.Log(Advertisement.IsReady().ToString());
if (Advertisement.IsReady("rewardedVideo")) {
Debug.Log(Advertisement.IsReady().ToString());
var options = new ShowOptions { resultCallback = HandleShowResult };
Advertisement.Show("rewardedVideo", options);
} else if (!Advertisement.IsReady("rewardedVideo")) {
gameManager.AdFailed.gameObject.SetActive(true);
Invoke("DeactivateAdFailUi", 5f);
}
}
private void HandleShowResult (ShowResult result) {
switch (result) {
case ShowResult.Finished:
gameManager.numberOfTimesAdsSeen = gameManager.numberOfTimesAdsSeen + 1;
if (gameManager.numberOfTimesAdsSeen == 1) {
gameManager.deathCount = 3;
Invoke("Reward2Lives", 0.5f);
} else if(gameManager.numberOfTimesAdsSeen == 2) {
gameManager.deathCount = 5;
Invoke("Reward1Life", 0.5f);
}
gameManager.AdOption.gameObject.SetActive(false);
gameManager.SpawnOptionsActivate();
Debug.Log("The ad was successfully shown.");
break;
case ShowResult.Skipped:
Debug.Log("The ad was skipped before reaching the end.");
break;
case ShowResult.Failed:
Debug.LogError("The ad failed to be shown.");
gameManager.AdFailed.gameObject.SetActive(true);
Invoke("DeactivateAdFailUi", 5f);
break;
}
}
void DeactivateAdFailUi() {
gameManager.AdFailed.gameObject.SetActive(false);
}
void Reward2Lives() {
lifeManager.Lives[2].gameObject.SetActive(true);
lifeManager.Lives[3].gameObject.SetActive(true);
lifeManager.Lives[4].gameObject.SetActive(true);
}
void Reward1Life() {
//lifeManager.Lives[3].gameObject.SetActive(true);
lifeManager.Lives[4].gameObject.SetActive(true);
}
}
Here is my code and I can’t seem to figure out whats going on! During test ads there was nothing wrong. But after I have uploaded the game onto the play store, I try it on my S4, the game restarts from the beginning once I watch a reward ad, from a whole new scene, which is an intro scene, I have to go to the playing scene. This problem doesn’t seem to show up on my tab 3 10.1" though.
Does anyone know where to look? Searching the forums, it seems the problem was apparently fixed in a previous version. I have got version 5.6.1f1 and ads version is 2.0. I believe thats the ads version because I got the ads service from the service tab in the editor.
Update: The problem seems to show up on all mobile phones that I have tested on. I only tried it on one tablet and that the only place its working properly.