Admob Unity Plugin provides a way to integrate admob ads in Unity3D Game and u3d app. You can use it for Unity iOS and Android App with the same c# or js code.
- Admob Unity Plugin Description
- Unity Admob Plugin Features
- Downloads Admob Unity Plugin
- Installation Admob Unity
- Unity Plugin Wiki and Documentation
- Quick Start
- Unity Admob Demo Usage
- Important Tips
- Screenshots
- License
The Google Mobile Ads SDK is the latest generation in Google mobile advertising featuring refined ad formats and streamlined APIs for access to mobile ad networks and advertising solutions. The SDK enables Unity mobile app developers to maximize their monetization in native mobile apps.
This repository contains the source code for the Google Mobile Ads Unity plugin. This plugin enables Unity developers to easily serve Google Mobile Ads on Android and iOS apps without having to write Java or Objective-C code. The plugin provides a C# interface for requesting ads that is used by C# scripts in your Unity project.
Platforms supported in one plugin :
- Android, via SDK v7.8 (part of Google Play service platform)
- iOS, via SDK v7.6.0
- Support all native events
- AdRequest targeting methods,such as children target,test mode
- Not need change Android package name
- Very simple API
Ad Types:
- Banner(All Banner Type and Custom banner sizes)
- Interstitial (text, picture, video)
- Rewarded Video
AdmobPluginRes/GoogleMobileAds.framework and admob_unity_plugin.unitypackage is reqired
Download those files from Admob Unity3d Plugin Project Home https://github.com/unity-plugins/Unity-Admob
or Download all the Unity admob plugin project https://github.com/unity-plugins/Unity-Admob/archive/master.zip
- Open your project in the Unity editor.
- Navigate to Assets -> Import Package -> Custom Package.
- Select the AdmobUnityPlugin.unitypackage file.
- Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.
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
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
By default, banners are visible. To temporarily hide a banner, call:
Admob.Instance().removeBanner();
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();
}
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);
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);
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.
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();
}
- import AdmobUnityPlugin.unitypackage to your Unity project
- copy admobdemo.cs from AdmobPluginRes to your unity project/assets dic
- attach admobdemo.cs to the main camera
- edit admob id in admobdemo.cs
- build and run this in your device
- Add GoogleMobileAds.framework. to Xcode Project
- Add the following framework to Xcode project
AdSupport.framework,EventKit.framework,EventKitUI.framework,CoreTelephony.framework,StoreKit.framework,MessageUI.framework