Advertisemen
Requirements -
- Unity 4.3 or higher
- An ad unit ID
- To deploy on Android:
- Android SDK 3.2 or higher
- Google Play services 4.0 or higher
- To deploy on iOS:
- XCode 5.1 or above
- Google Mobile Ads SDK
- Google Mobile Ads Unity Plugin v2.1
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 -
- Add the Google Mobile Ads iOS SDK library [ make sure you added into Library folder in Xcode].
- Add the following frameworks if they aren't already part of the project:
- AdSupport
- AudioToolbox
- AVFoundation
- CoreGraphics
- CoreTelephony
- MessageUI
- StoreKit
- SystemConfiguration
- Add the -ObjC linker flag to your Other Linker Flags in Build Settings.
- 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(adUnitIdBanner, AdSize.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 ex. on game over
void CallInterstitial () {
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
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(adUnitIdBanner, AdSize.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 ex. on game over
void CallInterstitial () {
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
For more information ---
Advertisemen
Tidak ada komentar:
Posting Komentar