Download AdMob
https://www.dropbox.com/s/psjtu5vn12m3fzl/googleadmob.unitypackage?dl=0
Import Pakage to Unity
Goto C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androidplayer here you find AndroidManifest.XML
Copy it to Assets\Plugin\Android
Open the AndroidManifest.xml and add the following inside the
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Also the following permissions under the
And finally you'll need to add or modify the metadata information for the
So it becomes.
Create a Script file in my case I lvove to write code in C# so
Admob.cs
private const string AD_UNIT_ID = "";
private AdMobPlugin adMob;
private const string AD_INTERSINAL = "";
private bool hidden=true;
// Use this for initialization
void Awake () {
DontDestroyOnLoad(this);
}
// Update is called once per frame
void Start ()
{
adMob = GetComponent<AdMobPlugin>();
adMob.CreateBanner(AD_UNIT_ID, AdMobPlugin.AdSize.SMART_BANNER, true, AD_INTERSINAL);
adMob.RequestAd();
adMob.HideBanner();
}
public void OnClickShowAds()
{
if (hidden)
{
adMob.ShowBanner();
hidden = false;
}
}
public void OnClickHideAds()
{
if (!hidden)
{
adMob.HideBanner();
hidden = true;
}
}
public void OnClickIntantialAds()
{
adMob.RequestInterstitial();
}
public void OnEnable()
{
AdMobPlugin.InterstitialLoaded+=AdMobPlugin_InterstitialLoaded;
}
public void OnDisable()
{
AdMobPlugin.InterstitialLoaded -= AdMobPlugin_InterstitialLoaded;
}
public void AdMobPlugin_InterstitialLoaded()
{
adMob.ShowInterstitial();
}
Just paste the admod AD id and intenstion ID.
Finally Attach this and admob script to MainCamera .
https://www.dropbox.com/s/psjtu5vn12m3fzl/googleadmob.unitypackage?dl=0
Import Pakage to Unity
Goto C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androidplayer here you find AndroidManifest.XML
Copy it to Assets\Plugin\Android
Open the AndroidManifest.xml and add the following inside the
<application>
tag: <activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Also the following permissions under the
<manifest>
tag:<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And finally you'll need to add or modify the metadata information for the
UnityPlayerNativeActivity
otherwise the ads won't be clickable.So it becomes.
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
Create a Script file in my case I lvove to write code in C# so
Admob.cs
private const string AD_UNIT_ID = "";
private AdMobPlugin adMob;
private const string AD_INTERSINAL = "";
private bool hidden=true;
// Use this for initialization
void Awake () {
DontDestroyOnLoad(this);
}
// Update is called once per frame
void Start ()
{
adMob = GetComponent<AdMobPlugin>();
adMob.CreateBanner(AD_UNIT_ID, AdMobPlugin.AdSize.SMART_BANNER, true, AD_INTERSINAL);
adMob.RequestAd();
adMob.HideBanner();
}
public void OnClickShowAds()
{
if (hidden)
{
adMob.ShowBanner();
hidden = false;
}
}
public void OnClickHideAds()
{
if (!hidden)
{
adMob.HideBanner();
hidden = true;
}
}
public void OnClickIntantialAds()
{
adMob.RequestInterstitial();
}
public void OnEnable()
{
AdMobPlugin.InterstitialLoaded+=AdMobPlugin_InterstitialLoaded;
}
public void OnDisable()
{
AdMobPlugin.InterstitialLoaded -= AdMobPlugin_InterstitialLoaded;
}
public void AdMobPlugin_InterstitialLoaded()
{
adMob.ShowInterstitial();
}
Just paste the admod AD id and intenstion ID.
Finally Attach this and admob script to MainCamera .
Comments
Post a Comment