Skip to content

How to Use Admob Plugin for Unity

unity-plugins edited this page Sep 20, 2019 · 7 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.

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().initSDK( new AdProperties());//set your admob id here
		            Admob.Instance().showBannerRelative("your admob banner id",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 id meta

<!--Admob Settings-->
<meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="your admob app id"/>

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. add -ObjC flag in xcode Other Linker Flags 3 add meta app key in Xcode Info.plist

    GADApplicationIdentifier ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxxxxxxx

  3. Click IOS platform ,Build and Run

  4. connect your ios device to mac,and click run to test this project

You can’t perform that action at this time.