Banner Integration for Unity
Banner ads usually appear at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.
Here is how you would create a banner in the Unity Script file - make sure you only call this once in the lifecycle of your app: Make sure your script is “using System”.
Create a banner
MoPub.createBanner (bannerAdUnit, MoPubAdPosition.BottomRight);
Show/hide the banner (optional - the banner is shown by default)
MoPub.showBanner (bannerAdUnit, true); MoPub.showBanner (bannerAdUnit, false); // hides the banner
Destroy the banner:
MoPub.destroyBanner (bannerAdUnit); MoPub.destroyBanner (bannerAdUnit);
If your game is distributed on iOS and Android, you only need to import the plugin only once, but you need to create different ad units per OS:
```csharp #if UNITY_IOS MoPub.createBanner("REPLACE_BY_IPHONE_AD_UNIT_ID_HERE", MoPubAdPosition.BottomCenter ); #elif UNITY_ANDROID MoPub.createBanner("REPLACE_BY_ANDROID_AD_UNIT_ID_HERE", MoPubAdPosition.BottomCenter ); #endif ```
Here are the banner-related callback handlers:
```csharp void onAdLoaded (string height) void onAdFailed (string errorMsg) void onAdClicked (string adUnitId) void onAdExpanded (string adUnitId) void onAdCollapsed (string adUnitId) ```
- Only create a banner ad view when you display it to the user.
- If the user navigates from a screen with a banner on it to a screen that does not have a banner, you should destroy or hide the banner.
Last updated December 13, 2018
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2018 MoPub Inc.