unity-plugins edited this page Feb 22, 2017 · 3 revisions
  1. Install
  2. Code
  3. Set For Android
  4. build for Android
  5. build for IOS

Install

  1. Open your project in the Unity editor.
  2. Navigate to Assets -> Import Package -> Custom Package.
  3. Select the admob_unity_plugin.unitypackage file.
  4. Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files. ScreenShot

Code

  1. add a c# script
  2. drag that script to object on scene such as main camera
  3. 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);
		        }
		}
	}

Set For Android

This Step Is not reqired for new version any more. if your unity project has a AndroidManifest.xml,then you need add admob activity

<!--Admob Settings-->
<meta-data android:name="com.google.android.gms.version"
android:value="8115000" />
<activity
     android:name="com.google.android.gms.ads.AdActivity"
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
     android:theme="@android:style/Theme.Translucent" />

and make sure your AndroidManifest.xml contains permissions

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

build for Android

Unity Admob Plugin not need edit android project ,so you can compile and run the android apk directly from the Unity Editor

  1. connect your android device to pc
  2. Navigate to **File -> Build Settings -> Android Platform **.
  3. Click Android platform ,Build and Run

build for IOS

  1. Navigate to ** File -> Build Settings -> IOS Platform ** .

  2. Click IOS platform ,Build and Run

  3. Set Xcode Project

    • Open ios project exported from unity with xcode
    • copy GoogleMobileAds.framework to ios project
    • **File->Add files to project ->select GoogleMobileAds.framework and add it to ios project
    • change to xcode project build setting tab
    • add follow frameworks AdSupport.framework,EventKit.framework,EventKitUI.framework,CoreTelephony.framework,StoreKit.framework,MessageUI.framework
  4. connect your ios device to mac,and click run to test this project

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.