Quantcast
Channel: Questions in topic: "ads"
Viewing all articles
Browse latest Browse all 1416

How can i make a Google Mobile Adsense in my Unity game ??

$
0
0
when i use the Google Mobile Ads plugins,the banner appear but if i click on he's doesn't work. Can you help me . I use this code: using System; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api; // Example script showing how to invoke the Google Mobile Ads **Unity** plugin. public class GoogleMobileAdsDemoScript : MonoBehaviour { public GUISkin GuiSkinBanner; private BannerView bannerView; private InterstitialAd interstitial; void Update() { RequestBanner (); } void OnGUI() { GUI.skin = GuiSkinBanner; Rect showBannerRect = new Rect(Screen.width/2-160,Screen.height-50, 320,50); if (GUI.Button(showBannerRect, "")) { bannerView.Show(); } } private void RequestBanner() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-8800874330043208/1754401517"; #elif UNITY_IPHONE string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE"; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x50 banner at the top of the screen. bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom); // Register for ad events. bannerView.AdLoaded += HandleAdLoaded; bannerView.AdFailedToLoad += HandleAdFailedToLoad; bannerView.AdOpened += HandleAdOpened; bannerView.AdClosing += HandleAdClosing; bannerView.AdClosed += HandleAdClosed; bannerView.AdLeftApplication += HandleAdLeftApplication; // Load a banner ad. bannerView.LoadAd(createAdRequest()); } private void RequestInterstitial() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-8800874330043208/1754401517"; #elif UNITY_IPHONE string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE"; #else string adUnitId = "unexpected_platform"; #endif // Create an interstitial. interstitial = new InterstitialAd(adUnitId); // Register for ad events. interstitial.AdLoaded += HandleInterstitialLoaded; interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad; interstitial.AdOpened += HandleInterstitialOpened; interstitial.AdClosing += HandleInterstitialClosing; interstitial.AdClosed += HandleInterstitialClosed; interstitial.AdLeftApplication += HandleInterstitialLeftApplication; // Load an interstitial ad. interstitial.LoadAd(createAdRequest()); } // Returns an ad request with custom ad targeting. private AdRequest createAdRequest() { return new AdRequest.Builder() .AddTestDevice(AdRequest.TestDeviceSimulator) .AddTestDevice("0123456789ABCDEF0123456789ABCDEF") .AddKeyword("game") .SetGender(Gender.Male) .SetBirthday(new DateTime(1985, 1, 1)) .TagForChildDirectedTreatment(false) .AddExtra("color_bg", "9B30FF") .Build(); } private void ShowInterstitial() { if (interstitial.IsLoaded()) { interstitial.Show(); } else { print("Interstitial is not ready yet."); } } #region Banner callback handlers public void HandleAdLoaded(object sender, EventArgs args) { print("HandleAdLoaded event received."); } public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) { print("HandleFailedToReceiveAd event received with message: " + args.Message); } public void HandleAdOpened(object sender, EventArgs args) { print("HandleAdOpened event received"); } void HandleAdClosing(object sender, EventArgs args) { print("HandleAdClosing event received"); } public void HandleAdClosed(object sender, EventArgs args) { print("HandleAdClosed event received"); } public void HandleAdLeftApplication(object sender, EventArgs args) { print("HandleAdLeftApplication event received"); } #endregion #region Interstitial callback handlers public void HandleInterstitialLoaded(object sender, EventArgs args) { print("HandleInterstitialLoaded event received."); } public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args) { print("HandleInterstitialFailedToLoad event received with message: " + args.Message); } public void HandleInterstitialOpened(object sender, EventArgs args) { print("HandleInterstitialOpened event received"); } void HandleInterstitialClosing(object sender, EventArgs args) { print("HandleInterstitialClosing event received"); } public void HandleInterstitialClosed(object sender, EventArgs args) { print("HandleInterstitialClosed event received"); } public void HandleInterstitialLeftApplication(object sender, EventArgs args) { print("HandleInterstitialLeftApplication event received"); } #endregion }

Viewing all articles
Browse latest Browse all 1416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>