1

I'm trying to integrate ads but the problem is rewarded ad isn't showing. However Interstitial ad does work. The scene waits for 2,3 seconds and shows interstitial ads but doesn't show rewarded ads, even though in log it does show "SHOW AD XXX".

Here is the gamescript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gamescript: MonoBehaviour {

    public static bool isGameover;

    // Use this for initialization
    void Start() {
        isGameover = false;
        Invoke("GameOver", 2);
    }

    // Update is called once per frame
    void Update() {

    }

    void GameOver() {
        isGameover = true;
        Debug.Log("Game Over");
    }
}

and here is my rewarded ad script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class Newreward: MonoBehaviour {

    private RewardBasedVideoAd rewardBasedVideo;
    bool hasShownAdOneTime;

    // Use this for initialization
    void Start() {
        rewardBasedVideo = RewardBasedVideoAd.Instance;

        // Called when the user should be rewarded for watching a video.
        rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
        // Called when the ad is closed.
        rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
        LoadRewardBasedAd();

    }

    // Update is called once per frame
    void Update() {
        if (Gamescript.isGameover) {
            if (!hasShownAdOneTime) {
                hasShownAdOneTime = true;
                Invoke("ShowRewardBasedAd", 3);
            }
        }
    }

    public void LoadRewardBasedAd() {
        #if UNITY_EDITOR
        string adUnitId = "unused";
        #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/5224354917";
        #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/1712485313";
        #else
            string adUnitId = "unexpected_platform";
        #endif

        rewardBasedVideo.LoadAd(new AdRequest.Builder().Build(), adUnitId);
    }

    public void ShowRewardBasedAd() {
        if (rewardBasedVideo.IsLoaded()) {
            rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
            rewardBasedVideo.Show();

            Debug.Log("SHOW AD XXX");
        } else {
            MonoBehaviour.print("Dude no ad");
        }
    }

    public void HandleRewardBasedVideoClosed(object sender, System.EventArgs args) {
        this.LoadRewardBasedAd();
    }

    public void HandleRewardBasedVideoRewarded(object sender, Reward args) {
        string type = args.Type;
        double amount = args.Amount;
        MonoBehaviour.print("HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " + type);
    }
}

any help would be appreciated

Programmer
  • 121,791
  • 22
  • 236
  • 328
melissa
  • 375
  • 1
  • 8
  • 20

0 Answers0