Adding Admob [Google mobile Ads ] in your Unity3D projects

Advertisemen


Requirements -


First step - 
Import google mobile ads unity plugin into your project [Assets > Import Package > Custom Package].

Second Step -
For Android -
If you already had an AndroidManifest.xml in Unity project Assets/Plugins/Android/, keep your current version and add the necessary activities and permissions required by the Google Mobile Ads SDK.

Additional dependencies:
 - Add the google-play-services_lib folder, located at sdk/extras/google/google_play_services/libproject [ it is inside ADT file you downloaded from android website], into the Plugins/Android folder of your project.
For iOS
Go ahead build and run your project for iOS. Then in Xcode do the followings -
  1. Add the Google Mobile Ads iOS SDK library [ make sure you added into Library folder in Xcode].
  2. Add the following frameworks if they aren't already part of the project:
    • AdSupport
    • AudioToolbox
    • AVFoundation
    • CoreGraphics
    • CoreTelephony
    • MessageUI
    • StoreKit
    • SystemConfiguration
  3. Add the -ObjC linker flag to your Other Linker Flags in Build Settings.
  4. If you got any errors like link-O or link-l when you complied, change search path under Build Setting > Search Paths > Library Search Paths like so (assuming you have saved your project in the desktop) Users/your computer name/Desktop/Project name/libraries.
Third Step -
Type or copy paste followings in the script where you want to call ads -

using UnityEngine;
using System.Collections;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class adMob MonoBehaviour {
    private InterstitialAd interstitial;

    // Use this for initialization
    void Start () {
        // Intersitial ads go here
        
        #if UNITY_ANDROID
         string adUnitId = "xxxxxxxxxxxxxx";
        #elif UNITY_IPHONE
         string adUnitId = "xxxxxxxxxxxxxx";
        #endif
        
        
        // Create an interstitial.
         interstitial = new InterstitialAd(adUnitId);
        // Load an interstitial ad.
         interstitial.LoadAd(new AdRequest.Builder().Build());
        // intersitial ads end here.................................
        
        
        //Banner ads start here.....................................
        // Create a 320x50 banner at the top of the screen.
        #if UNITY_ANDROID
        string adUnitIdBanner = "xxxxxxxxxxxxxxxxx";
        #elif UNITY_IPHONE
        string adUnitIdBanner = "xxxxxxxxxxxxxxxxx";
        #endif
        
        BannerView bannerView = new BannerView(adUnitIdBannerAdSize.Banner

                                                 AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the banner with the request.
        bannerView.LoadAd(request);
        //Banner ads end here
    }
    
    // call this function whenever you want ad to display exon game over
    void CallInterstitial () {
        if (interstitial.IsLoaded())
        {
            interstitial.Show();
        }
    }
}

For more information ---

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D