How to install Admob Unity3d Plugin : Step by Step with Picture


admob unity3d plugin

Unity Admob Plugin is Admob SDK plugin for Unity3d ,this plugin make js and c# developer easy to add google ads in Unity3d games,support IOS and Android ,support admob interstitial and smart banner.

Download Unity3d Admob SDK plugin.

How to install Admob Unity3d Plugin?

First open your project in the Unity editor.
Navigate to Assets -> Import Package -> Custom Package.

unity3d custom pakacage
Select the admob_unity_plugin.unitypackage file.Import all of the files for the plugins by selecting Import.
Make sure to check for any conflicts with files.

admob unity3d code

Next Step add a c# scriptdrag that script to object on scene such as main cameraa
Add admob relatived code,this will add a banner on screen
 using UnityEngine;
    using System.Collections;
    using admob;
    public class admobdemo : MonoBehaviour {
        void OnGUI(){
                if (GUI.Button(new Rect(240, 100, 100, 60), "showbanner"))
                {
                Admob.Instance().initAdmob("ca-app-pub-279604544xxxxx0/xxxxxxxxx", "ca-app-pub-279xxxxxxx0/xxxxxxxxxxx");//set your admob id here
                    Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
                }
        }
    }


Now you can build and run on Android Devices.

Quick Guide

1. How to initialize 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. How 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);


3. How to  Remove Admob Banner ini Unity3d

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.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();

    }


For more detail please visit the plugins website.



Full Code


using UnityEngine;
using System.Collections;
using admob;
public class admobdemo : MonoBehaviour {
// Use this for initialization
void Start () {
        Admob.Instance().bannerEventHandler += onBannerEvent;
        Admob.Instance().interstitialEventHandler += onInterstitialEvent;
        Admob.Instance().rewardedVideoEventHandler += onRewardedVideoEvent;
       
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if (GUI.Button (new Rect (0, 0, 100, 60), "initadmob")) {
            Admob ad = Admob.Instance();
         
            ad.initAdmob("ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx", "ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxxx");
         
         //   ad.setTesting(true);
}
        if (GUI.Button(new Rect(120, 0, 100, 60), "showInterstitial"))
        {
            Admob ad = Admob.Instance();
            if (ad.isInterstitialReady())
            {
                ad.showInterstitial();
            }
            else
            {
                ad.loadInterstitial();
            }
        }
        if (GUI.Button(new Rect(240, 0, 100, 60), "showRewardVideo"))
        {
            Admob ad = Admob.Instance();
            if (ad.isRewardedVideoReady())
            {
                ad.showRewardedVideo();
            }
            else
            {
                ad.loadRewardedVideo("ca-app-pub-xxxxxxxxxxxxxxxxxx/xxxxxxxxxx");
            }
        }
        if (GUI.Button(new Rect(240, 100, 100, 60), "showbanner"))
        {
            Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
        }
        if (GUI.Button(new Rect(240, 200, 100, 60), "showbannerABS"))
        {
            Admob.Instance().showBannerAbsolute(AdSize.Banner, 0, 30);
        }
        if (GUI.Button(new Rect(240, 300, 100, 60), "hidebanner"))
        {
            Admob.Instance().removeBanner();
        }
}
    void onInterstitialEvent(string eventName, string msg)
    {
        Debug.Log("handler onAdmobEvent---" + eventName + "   " + msg);
        if (eventName == AdmobEvent.onAdLoaded)
        {
            Admob.Instance().showInterstitial();
        }
    }
    void onBannerEvent(string eventName, string msg)
    {
        Debug.Log("handler onAdmobBannerEvent---" + eventName + "   " + msg);
    }
    void onRewardedVideoEvent(string eventName, string msg)
    {
        Debug.Log("handler onRewardedVideoEvent---" + eventName + "   " + msg);
    }
}

How to install Admob Unity3d Plugin : Step by Step with Picture How to install Admob Unity3d Plugin : Step by Step with Picture Reviewed by Admin on 6:22 AM Rating: 5

No comments:

Home Ads

Powered by Blogger.