How to Use Admob Plugin for Unity
Install
- Open your project in the Unity editor.
- Navigate to Assets -> Import Package -> Custom Package.
- Select the admob_unity_plugin.unitypackage file.
- Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.
Code
- add a c# script
- drag that script to object on scene such as main camera
- 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
- connect your android device to pc
- Navigate to **File -> Build Settings -> Android Platform **.
- Click Android platform ,Build and Run
build for IOS
-
Navigate to ** File -> Build Settings -> IOS Platform ** .
-
add -ObjC flag in xcode Other Linker Flags 3 add meta app key in Xcode Info.plist
GADApplicationIdentifier ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxxxxxxx
-
Click IOS platform ,Build and Run
-
connect your ios device to mac,and click run to test this project