Unity3D How to Unity Ads reward video in Android ( Google Android Unity 광고 개시 , 보상형광고편)
Import Admob plugin
Google Mobile Ads Unity Plugin DownLoad Link
Android
- Import Unity plugin
Assets-> Import Package ->Custom Packages...
- All Import! - Done !
Unity c# Script
using System.Collections;
using System;
using UnityEngine;
using GoogleMobileAds.Api;
public class TestAds : MonoBehaviour{
private String appId = "Your app Id is Here ";
private String appUnitId = "Your app Unit Id is Here ";
private RewardBasedVideoAd rewardVideo;
private void Start(){
#if UNITY_ANDROID
MobileAds.Initialize(appId);
// Initialize video
this.rewirdVideo = RewardBasedVideoAd.Instance;
// create Video Instance
rewirdVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
// Load success called
rewirdVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
// Load Fail called
rewirdVideo.OnAdOpening += HandleRewardBasedVideoOpened;
// Video open called
rewirdVideo.OnAdStarted += HandleRewardBasedVideoStarted;
// Video Ads Play called
rewirdVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
// User get reward called
rewirdVideo.OnAdClosed += HandleRewardBasedVideoClosed;
// Video end called
rewirdVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
// Leaving Application called (Move Playstore , Website ,etc..)
this.requestRewardBasedVideo();
// Reward video core code!
// this Function VideoAds load.
#endif
} // Start End..
private void requestRewardBasedVideo() {
AdRequest req = new AdRequest.Builder().Build();
this.rewirdVideo.LoadAd(req, appUnitId);
}
// Ad load Core Function.
private void showAd() {
if(rewirdVideo.IsLoaded()) { // Video is Loaded check logical.
rewirdVideo.Show(); // show reward video.
}
}
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args) {
Debug.Log("HandleRewardBasedVideoLoaded event received");
}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args) {
Debug.Log(
"HandleRewardBasedVideoFailedToLoad event received with message: "
+ args.Message);
}
public void HandleRewardBasedVideoOpened(object sender, EventArgs args) {
// Here view User CPR
// If you check the Analytics and add in code this
Debug.Log("HandleRewardBasedVideoOpened event received");
}
public void HandleRewardBasedVideoStarted(object sender, EventArgs args) {
Debug.Log("HandleRewardBasedVideoStarted event received");
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args) {
Debug.Log("HandleRewardBasedVideoClosed event received");
this.requestRewardBasedVideo();
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args) {
string type = args.Type;
double amount = args.Amount;
Debug.Log( "event received for " + amount.ToString() + " " + type);
}
public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args) {
Debug.Log("HandleRewardBasedVideoLeftApplication event received");
}
public void ButtonOnClick(){
#if UNITY_ANDROID
showAd();
#endif
}
}
Unity button Onclick function add " ButtonOnClick()";
[Solved] Unity3D admob EventArgs not found Error
// Add using System
using System;
Unity3d AdMob - AndroidJavaException: java.lang.ClassNotFoundException (0) | 2019.08.20 |
---|---|
Unity3D Load Json StreamingAsssets Path in Android Solution (0) | 2019.07.24 |
Unity Scroll view solution (Version 2018 3.12f1) (31) | 2019.04.19 |
Unity 화면크기 가져오기. (0) | 2019.01.30 |
Unity3D Android Logcat (0) | 2019.01.18 |
Unity mouse Drag object/ Touch moved (0) | 2019.01.15 |