- Home /
Answer For -> How to Reward Player after watching video - admob rewarded video
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class AdmobGetHub : MonoBehaviour
{
private RewardBasedVideoAd rewardBasedVideoAd;
bool rewardPlayer = false;
// Use this for initialization
void Start()
{
this.rewardBasedVideoAd = RewardBasedVideoAd.Instance;
this.LoadRewardBasedAd();
// has rewarded the user.
this.rewardBasedVideoAd.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
// Update is called once per frame
void Update()
{
if (rewardPlayer == true)
{
// do all the actions
// Reward the player Her <=================
msg.SetActive(true);
rewardPlayer = false; // to make sure this action will happen only once.
}
}
//-------------------------------------------------------------------------------------
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
//Production
AdRequest adRequest = new AdRequest.Builder ().Build ();
//Test
//AdRequest adRequest = new AdRequest.Builder()
//.AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator.
//.AddTestDevice("c78b1468accb7ee846fa4f8e61bde0ff") // My test device.
//.Build();
//Load ad
this.rewardBasedVideoAd.LoadAd(new AdRequest.Builder().Build(), adUnitId);
}
public void ShowRewardBasedAd()
{
if (this.rewardBasedVideoAd.IsLoaded())
{
this.rewardBasedVideoAd.Show();
}
else
{
this.LoadRewardBasedAd();
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
rewardPlayer = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
VideoPlayer not playing in WebGL Build 0 Answers
why isn't the video playing from my assets? 0 Answers
Video not working on Android 1 Answer
Can handheld.PlayfullScreenMovie() work with Vr view to play 360 degree video using google vr sdk? 0 Answers
Cannot import video of any type in Ubuntu Unity 5.6.1xf1 1 Answer