-
-
Save PrerakPrek/4925e42610e76551c6fa15851a22ca79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using GoogleMobileAds; | |
| using GoogleMobileAds.Api; | |
| public class AdShower : MonoBehaviour | |
| { | |
| InterstitialAd interstitial; | |
| // Use this for initialization | |
| void Start() | |
| { | |
| RequestBanner(); | |
| RequestInterstitial(); | |
| } | |
| public void showInterstitialAd() | |
| { | |
| //Show Ad | |
| if (interstitial.IsLoaded()) | |
| { | |
| Debug.Log ("Shown"); | |
| interstitial.Show(); | |
| } | |
| } | |
| private void RequestBanner() | |
| { | |
| #if UNITY_EDITOR | |
| string adUnitId = "unused"; | |
| #elif UNITY_ANDROID | |
| string adUnitId = "ca-app-pub-4697579006360442/5518347117"; | |
| #elif UNITY_IPHONE | |
| string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE"; | |
| #else | |
| string adUnitId = "unexpected_platform"; | |
| #endif | |
| // Create a 320x50 banner at the bottom of the screen. | |
| BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom); | |
| // Create an empty ad request. | |
| AdRequest request = new AdRequest.Builder().Build(); | |
| // Load the banner with the request. | |
| bannerView.LoadAd(request); | |
| } | |
| private void RequestInterstitial() | |
| { | |
| #if UNITY_ANDROID | |
| string adUnitId = "ca-app-pub-5296704173419386/6037278325"; | |
| #elif UNITY_IPHONE | |
| string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE"; | |
| #else | |
| string adUnitId = "unexpected_platform"; | |
| #endif | |
| // Initialize an InterstitialAd. | |
| interstitial = new InterstitialAd(adUnitId); | |
| // Create an empty ad request. | |
| AdRequest request = new AdRequest.Builder().Build(); | |
| // Load the interstitial with the request. | |
| interstitial.LoadAd(request); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment