상세 컨텐츠

본문 제목

Unity3D How to Unity Ads reward video in Android ( Google Android Unity 광고 개시 , 보상형광고편)

개발생활/Unity Engine

by 한국인맛집 2019. 2. 13. 19:43

본문

반응형

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



Add namespace

using GoogleMobileAds.Api;

 

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;







반응형

관련글 더보기