[SOLVED]Can anyone help me with a script for a rewarded video that removes ads for X mins please?

Hi!

I am very much a beginner at Unity/C# but I have built a simple, 3 scene game using Unity (welcome page, game page, game over page). It will be published on Play Store and The App Store (Android and iOS) but I am now stuck on implementing Unity Ads.

I have managed to get a simple ad appear every 5 times the “play again” button is pressed via this script:

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

public class AdManager : MonoBehaviour
{
    static int loadCount = 0;

    void Start()
    {
        if (loadCount % 5 == 0)  //  show ad every 5th time
        {
            ShowAd();
        }
        loadCount++;
    }

    public void ShowAd()
    {
        if (Advertisement.IsReady())
        {
            Advertisement.Show();
        }
    }
}

But now I am trying to offer players the ability to remove ads for “X” minutes (probably 15) by watching a rewarded video.

The thing is, I have found lot’s of tutorials for rewarded videos but none that reward the user by removing the ads and I am not very good at C# yet so I just can’t get this to work :frowning:

Can anyone help at all?

Any help much appreciated!

Posting solution in case someone comes across in future… With thanks to someone on another forum:

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

public class AdManager : MonoBehaviour
{
    private static int loadCount = 0;
    private static bool noAds = false;
    private static DateTime noAdsTime = new DateTime();

    void Start()
    {
        DateTime currentTime = DateTime.Now;

        if (noAdsTime != new DateTime())
            noAds = DateTime.Compare(currentTime, noAdsTime) < 0 ? true : false; //DateTime.Compare returns less than zero if currentTime is earlier than noAdsTime.

        if (loadCount % 5 == 0 && noAds == false)  //  show ad every 5th time
        {
            ShowAd();
        }
        loadCount++;
    }


    public void ActivateNoAds(int minutes)
    {
        Advertisement.Show();
        DateTime currentTime = DateTime.Now;
        noAdsTime = currentTime.AddMinutes(minutes);

    }
    public void ShowAd()
    {
        if (Advertisement.IsReady())
        {
            Advertisement.Show();
        }
    }
}
1 Like