Be patient..... we are fetching your source code.
Objectives
The main objective of this blog post is to explain how to implement Ads in Unity. This blog post is very useful to developers who don’t know anything about Ad or Ad Implementation in Unity. Here we go through the idea of how to implement Ad in unity by using AdMob SDK.
Unity supports many kind of Ad plugins. Here we are going to focus on how to implement it using AdMob.
Step 1 AdMob
This blog provide best practices for integrating banner as well as interstitial Ad. Any advertisers who willing to report advertised app’s installation can use this SDK. Reporting installation contains number of easy and simple steps and it will start AdMob session. This SDK basically provides banner ads and interstitial ads. Advertisers can implement any of them according to their requirement.
Following are the steps from which u can get brief idea about how to integrate AdMob SDK in Android as well as in iOS.
Step 2 Find or Create your App ID
You can find/ create your app IDs from following given link:
You can put banner as well as interstitial ads in their games using AdMob. It also provides links and popups for ads.
Step 3 Configuration
To access the AdMob SDK and register your application, you have to get your media ID.
- First of all, download latest available version of the SDK.
- Now, you have to import this SDK as a custom package.
AdMob Unity SDK can be integrate using c# or JavaScript code. Here you have to keep one thing in mind that, you have to test it only in devices, as Ads will not show in Unity editor/ xCode simulator.
Here, please check that all files are selected and click on import.
Step 4 Integrate in iOS
AdMob SDK for iOS supports only in XCode version 4.4.1 or later. You have to include following two libraries as it is required.
- AdSupport
- StoreKit
You can get more idea by following image:
Step 5 Integrate in Android
Here , You have to add following required permission into your AndroidManifest.xml File by using following line of code.
<!-- Required --><uses-permissionandroid:name="android.permission.INTERNET"/>
Now, add the required AdMob activity inside the application tag.
<application>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik"
android:value="true" />
</activity>
</application>
Integration:
You can Create Ad (Cache Ads in memory) using following line of code.
To Create Interstitial:
AdMob.requestInterstital(<ANDROID_INTERSTITIAL_ID>, <IOS_INTERSTITIAL_ID>);
You Show Ad (Display on Screen) using following line of code.
To Create Interstitial:
AdMob.requestInterstital(<ANDROID_INTERSTITIAL_ID>, <IOS_INTERSTITIAL_ID>);
To Display Interstitial:
AdMob.displayInterstital();
To Display Banner:
Developer can directly create and display BannerAd.
AdMob.createBanner ("<IOS_AD_UNIT_ID>", "<ANDROID_AD_UNIT_ID>", <ADMOB_BANNER_TYPE>, <ADMOB_BANNER_POSITION>);
Example:
AdMob.createBanner ("<IOS_AD_UNIT_ID>", "<ANDROID_AD_UNIT_ID>", AdMobBanner.SmartBanner, AdMobLocation.TopCenter);
To Hide Banner:
AdMob.destroyBanner ();
Step 6 Listeners
Listeners (which is also called Delegates/Callbacks) help you to follow Ad workflow. Whenever state of the Ad will change AdMob SDK will fore events respectively. It calls specific methods as per the callbacks. For example, if Ad is loaded successfully or not, you can identify whenever user click on Ad etc. Following line of code gives brief idea about it.
6.1 For Android
void OnEnable()
{
// Listen to all events for illustration purposes
AdMobAndroidManager.dismissingScreenEvent += dismissingScreenEvent;
AdMobAndroidManager.failedToReceiveAdEvent += failedToReceiveAdEvent;
AdMobAndroidManager.leavingApplicationEvent += leavingApplicationEvent;
AdMobAndroidManager.presentingScreenEvent += presentingScreenEvent;
AdMobAndroidManager.receivedAdEvent += receivedAdEvent;
AdMobAndroidManager.interstitialDismissingScreenEvent += interstitialDismissingScreenEvent;
AdMobAndroidManager.interstitialFailedToReceiveAdEvent += interstitialFailedToReceiveAdEvent;
AdMobAndroidManager.interstitialLeavingApplicationEvent += interstitialLeavingApplicationEvent;
AdMobAndroidManager.interstitialPresentingScreenEvent += interstitialPresentingScreenEvent;
AdMobAndroidManager.interstitialReceivedAdEvent += interstitialReceivedAdEvent;
}
void OnDisable()
{
// Remove all event handlers
AdMobAndroidManager.dismissingScreenEvent -= dismissingScreenEvent;
AdMobAndroidManager.failedToReceiveAdEvent -= failedToReceiveAdEvent;
AdMobAndroidManager.leavingApplicationEvent -= leavingApplicationEvent;
AdMobAndroidManager.presentingScreenEvent -= presentingScreenEvent;
AdMobAndroidManager.receivedAdEvent -= receivedAdEvent;
AdMobAndroidManager.interstitialDismissingScreenEvent -= interstitialDismissingScreenEvent;
AdMobAndroidManager.interstitialFailedToReceiveAdEvent -= interstitialFailedToReceiveAdEvent;
AdMobAndroidManager.interstitialLeavingApplicationEvent -= interstitialLeavingApplicationEvent;
AdMobAndroidManager.interstitialPresentingScreenEvent -= interstitialPresentingScreenEvent;
AdMobAndroidManager.interstitialReceivedAdEvent -= interstitialReceivedAdEvent;
}
void dismissingScreenEvent()
{
Debug.Log( "dismissingScreenEvent" );
}
void failedToReceiveAdEvent( string error )
{
Debug.Log( "failedToReceiveAdEvent: " + error );
}
void leavingApplicationEvent()
{
Debug.Log( "leavingApplicationEvent" );
}
void presentingScreenEvent()
{
Debug.Log( "presentingScreenEvent" );
}
void receivedAdEvent()
{
Debug.Log( "receivedAdEvent" );
}
void interstitialDismissingScreenEvent()
{
Debug.Log( "interstitialDismissingScreenEvent" );
}
void interstitialFailedToReceiveAdEvent( string error )
{
Debug.Log( "interstitialFailedToReceiveAdEvent: " + error );
}
void interstitialLeavingApplicationEvent()
{
Debug.Log( "interstitialLeavingApplicationEvent" );
}
void interstitialPresentingScreenEvent()
{
Debug.Log( "interstitialPresentingScreenEvent" );
}
void interstitialReceivedAdEvent()
{
Debug.Log( "interstitialReceivedAdEvent" );
}
6.2 For iOS
void OnEnable()
{
// Listen to all events for illustration purposes
AdMobManager.receivedAdEvent += adViewDidReceiveAdEvent;
AdMobManager.failedToReceiveAdEvent += adViewFailedToReceiveAdEvent;
AdMobManager.interstitialReceivedAdEvent += interstitialDidReceiveAdEvent;
AdMobManager.interstitialFailedToReceiveAdEvent += interstitialFailedToReceiveAdEvent;
}
Checkout other Ads Implementation in Unity:
I hope you find this blog very helpful while Implementing Ads in Unity using AdMob Let me know in comment if you have any question regarding Unity. I will reply you ASAP
Got an Idea of 3D Game Development ? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Unity 3D Game Development Company in India.
I am 2D Game developer and iOS Developer with an aspiration of learning new technology and creating a bright future in Information Technology.
Ads Implementation in Unity Using RevMob