AdMob Rewarded Video

Last updated : June 21, 2017

Posted by: Neel Gajjar

Requirements

- Unity 4 or higher
- To deploy on iOS    
   - Xcode 7.0 or higher
   - Google Mobile Ads SDK 7.7.0 or higher
- To deploy on Android
   - Android SDK 3.2 or higher
   - Google Play services 7.5 or higher




DownloadGoogleMobileAds.unitypackage

Import the plugin into your game

1. Open your project in the Unity editor.
Select Assets > Import Package > Custom Package and find the GoogleMobileAdsPlugin.unitypackage file you downloaded.

2. Make sure all of the files are selected and click Import.


Unity plugin API

You can use the common C# API in the Google Mobile Ads plugin to request the rewarded video. The code can be written once and deployed to both Android and iOS.


How to request for the rewarded video?

Let's understand it with code.


using GoogleMobileAds.Api;

...

private void RequestInterstitial()

{

    #if UNITY_ANDROID

        string adUnitId = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE";

    #elif UNITY_IPHONE

        string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";

    #else

        string adUnitId = "unexpected_platform";

    #endif   

   

// Creating an instance of RewardBasedVideoAd class.

RewardBasedVideoAd rewardBasedVideoAd = RewardBasedVideoAd.Instance;


//Create an empty ad request.

AdRequest request = new AdRequest.Builder().Build();

// Load the interstitial with the request & adUnitId.

rewardBasedVideoAd.LoadAd (request,adUnitId);

// EventHandlers

// Called when the user returned from the app after an ad click.

rewardBasedVideoAd.OnAdClosed += HandleOnAdClosed;

// Called when an ad request failed to load.

rewardBasedVideoAd.OnAdFailedToLoad += HandleOnAdFailedToLoad;

// Called when the ad click caused the user to leave the application.

rewardBasedVideoAd.OnAdLeavingApplication += HandleOnAdLeavingApplication;

// Called when an ad request has successfully loaded.

rewardBasedVideoAd.OnAdLoaded += HandleOnAdLoaded;

rewardBasedVideoAd.OnAdOpening += HandleOnAdOpening;

// Called when user see the full ad successfully.

rewardBasedVideoAd.OnAdRewarded += HandleOnAdRewarded;

// Called when user start to watch video ad.

rewardBasedVideoAd.OnAdStarted += HandleOnAdStarted;

}


You only need to register for the events you care about.

If you don't want to use any handler, no not call handler from our RequestInterstitial().


Unlike banner ads, we have to call reward video ads explicitly.

At an appropriate point in your game, such as when player dead & you want to give the player another chance, show video reward ad & resume players game.

Make sure video reward ad is ready before showing it.

private void AdRewardFunction()

{

if (rewardBasedVideoAd.IsLoaded ()) {

rewardBasedVideoAd.Show ();

}

}



Send SMS From Your Game - Unity3D

Send SMS From Your Game - Unity3D

In the game, you can use "prefer the game" feature or invite the friend(s) who...
Send Email From Your Game - Unity3D

Send Email From Your Game - Unity3D

In your game, it might be possible that user directly wants to send an email to...
Reduce a size of APK and IPA – Unity 3d

Reduce a size of APK and IPA – Unity 3d

For reducing APK size:In Unity 5.6.0f3 I have created a simple "Hello world"...
Unity3D vs. Cocos2DX

Unity3D vs. Cocos2DX

License: Unity 3D is paid while Cocos2DX is an open-source game...
Best 5 games made with Unity 3D

Best 5 games made with Unity 3D

1. Pokémon GODeveloped & Published by Niantic; when both Niantic &...
Integrate Banner Ad for iOS & Android using AdMob

Integrate Banner Ad for iOS & Android using AdMob

Requirements- Unity 4 or higher- To deploy on iOS     ...
Integrate Interstitial Ad for iOS & Android using AdMob

Integrate Interstitial Ad for iOS & Android using AdMob

Requirements- Unity 4 or higher- To deploy on iOS       -...
Submit a Game to AppStore

Submit a Game to AppStore

Steps to submit a Game to AppStore1. Switch platform as iOS and then make a...
Use Debug.Break() to pause the editor

Use Debug.Break() to pause the editor

Use Debug.Break() in your code to pause the editorDid you know that you can...
AdMob Rewarded Video

AdMob Rewarded Video

Requirements- Unity 4 or higher- To deploy on iOS       -...