Hi,
I am sorry if I am being repetitive, but I tried to find solution for the problem I am having and nothing until now.
This is my first game and I am working on it for 5 months now.
I recently implemented ads by following Awesome Tuts tutorial
It worked fine but I am having trouble trying to configure several rewardedvideos behavior…I checked about placements, tried to create several placements in Dashboard but no good.
I am using the code provided in Unity guide…I want the three following rewards:
- Button on home page to watch ad for coins;
- Pay coins, watch ad and revive on first death;
- If you die in second level, you can watch ad to skip the first level and go to second again.
I created three separeted AdManagers gameobjects, 3 differente scripts, but somehow the behaviors seems to be overlapping.
How should I really work with the different rewards?
public class Ads : MonoBehaviour, IUnityAdsListener
{
string GooglePlay_ID = "XXXXXX";
bool testMode = true;
string myPlacementId = "rewardedVideo";
[SerializeField]
private UIManager _uiManager;
// Start is called before the first frame update
void Start()
{
_uiManager = GameObject.Find("Canvas").GetComponent<UIManager>();
Advertisement.AddListener (this);
Advertisement.Initialize(GooglePlay_ID, testMode);
}
public void DisplayInterstitialAd()
{
Advertisement.Show();
}
public void DisplayVideoAd()
{
Advertisement.Show(myPlacementId);
}
public void ShowRewardedVideo() {
// Check if UnityAds ready before calling Show method:
if (Advertisement.IsReady(myPlacementId)) {
Advertisement.Show(myPlacementId);
}
else {
Debug.Log("Rewarded video is not ready at the moment! Please try again later!");
}
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
_uiManager.gear+=5;
_uiManager.UpdateGear();
Advertisement.RemoveListener(this);
}
else if (showResult == ShowResult.Skipped)
{
Debug.LogWarning ("NO REWARD!");
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning ("The ad did not finish due to an error.");
}
}
public void OnUnityAdsReady (string placementId) {
// If the ready Placement is rewarded, show the ad:
if (placementId == myPlacementId) {
// Optional actions to take when the placement becomes ready(For example, enable the rewarded ads button)
}
}
public void OnUnityAdsDidError (string message) {
// Log the error.
}
public void OnUnityAdsDidStart (string placementId) {
// Optional actions to take when the end-users triggers an ad.
}
// When the object that subscribes to ad events is destroyed, remove the listener:
public void OnDestroy() {
Advertisement.RemoveListener(this);
}