- Home /
Question by
NullyStudio · May 25, 2020 at 10:12 AM ·
c#scripting beginnerunity ads
how to stop rewards for DisplayInterstitialAD
so i have added ads for when u click on Buttons in my main menu new game , continue and quite and also have a button in my pause menu to watch an ad and if you finish the ad you get a life but the issue is when u click in the main menu on new game , continue or quite you are getting rewarded if you watch these ads. I only want the player to be rewarded for clicking on the watch a Ad to get a life button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class UnityMonetization : MonoBehaviour, IUnityAdsListener
{
public int livesToGive;
private LevelManager theLevelManager;
public bool ranOnce = false;
string GooglePlay_ID = "3588324";
bool TestMode = false;
string myPlacementId = "rewardedVideo";
// Start is called before the first frame update
void Start()
{
Advertisement.AddListener(this);
Advertisement.Initialize(GooglePlay_ID, TestMode);
}
public void DisplayInterstitialAD()
{
Advertisement.Show();
}
public void DisplayVideoAD()
{
Advertisement.Show(myPlacementId);
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
theLevelManager = FindObjectOfType<LevelManager>();
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
// Reward the user for watching the ad to completion.
Debug.LogWarning("You Get A Reward.");
if (!ranOnce)
{
ranOnce = true;
theLevelManager.addLives(livesToGive);
}
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad
Debug.LogWarning("You Do Not Get A Reward.");
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("The ad did not finish due to an error.");
}
}
Comment