Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Integrate AdMob onto Unity Android - step by step video Tutorial

Discussion in 'Community Learning & Teaching' started by MacyK, Jun 5, 2014.

  1. MacyK

    MacyK

    Joined:
    May 10, 2013
    Posts:
    15
    Last edited: Jul 2, 2014
  2. wuym67123

    wuym67123

    Joined:
    Jan 3, 2017
    Posts:
    11
    Text Tutorial
    https://github.com/unity-plugins/Unity-Admob
    Installation Admob Unity
    1. Open your project in the Unity editor.
    2. Navigate to Assets -> Import Package -> Custom Package.
    3. Select the AdmobUnityPlugin.unitypackage file.
    4. Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.
    Unity Plugin Wiki and Documentation
    Quick Start
    1.Init Admob Unity Plugin
    Create A C# script ,drag the script to a object on scene , add the follow code in the script file

    using admob;
    Admob.Instance().initAdmob("admob banner id", "admob interstitial id");//admob id with format ca-app-pub-279xxxxxxxx/xxxxxxxx


    2.Add Admob Banner in Unity App
    Here is the minimal code needed to show admob banner.

    Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);


    The AdPosition class specifies where to place the banner. AdSize specifies witch size banner to show

    3.Remove Banner
    By default, banners are visible. To temporarily hide a banner, call:

    Admob.Instance().removeBanner();

    4.How to integrate Interstitial into Unity 3d app?
    Here is the minimal code to create an interstitial.

    Admob.Instance().loadInterstitial();

    Unlike banners, interstitials need to be explicitly shown. At an appropriate stopping point in your app, check that the interstitail is ready before showing it:

    if (Admob.Instance().isInterstitialReady()) {
    Admob.Instance().showInterstitial();
    }

    5.Custom Admob Banner Ad Sizes
    In addition to constants on AdSize, you can also create a custom size:

    //Create a 250x250 banner.
    AdSize adSize = new AdSize(250, 250);
    Admob.Instance().showBannerAbsolute(adSize,0,30);

    6.Admob test Ads and children app
    If you want to test the ads or the your app with children target,you can set with admob unity plugin easy

    Admob.Instance().setTesting(true);
    Admob.Instance().setForChildren(true);
    string[] keywords = { "game","crash","male game"};
    Admob.Instance().setKeywords(keywords);

    7.Ad Events
    Both Banner and Interstitial contain the same ad events that you can register for. Here we'll demonstrate setting ad events on a interstitial,and show interstitial when load success:

    Admob.Instance().interstitialEventHandler += onInterstitialEvent;
    void onInterstitialEvent(string eventName, string msg)
    {
    Debug.Log("handler onAdmobEvent---" + eventName + " " + msg);
    if (eventName == AdmobEvent.onAdLoaded)
    {
    Admob.Instance().showInterstitial();
    }
    }

    You only need to register for the events you care about.

    8.How to integrate Admob Rewarded Video to Unity3d app?
    Here is the minimal code to create an admob video.

    Admob.Instance().loadRewardedVideo("ca-app-pub-312xxxxxxxxxxxx/xxxxxxxx");

    Simular with interstitial,video need to be explicitly shown at an appropriate stopping point in your app, check that the video is ready before showing it:

    if (Admob.Instance().isRewardedVideoReady()) {
    Admob.Instance().showRewardedVideo();
    }

    9.Show Admob Native Express Ad in IOS and Android App
    Here is the minimal code needed to show admob banner.

    Admob.Instance().showNativeBannerRelative(new AdSize(360,100), AdPosition.BOTTOM_CENTER, 0,"ca-app-pub-3940256099942544/2562852117");


    Unity Admob Demo Usage
    1. import AdmobUnityPlugin.unitypackage to your Unity project
    2. copy admobdemo.cs from AdmobPluginRes to your unity project/assets dic
    3. attach admobdemo.cs to the main camera
    4. edit admob id in admobdemo.cs
    5. build and run this in your device
    Important Tips
    1. Add GoogleMobileAds.framework. to Xcode Project
    2. Add the following framework to Xcode project
    AdSupport.framework,EventKit.framework,EventKitUI.framework,CoreTelephony.framework,StoreKit.framework,MessageUI.framework

     
  3. walidabazo

    walidabazo

    Joined:
    Jul 8, 2017
    Posts:
    17
    Show this videos unity 5.6.x and unity 2017