Quick Start using Unity Services
This guide provides a quick integration of Unity Ads into a Unity 5.3 game. The source code referenced here is available on our public GitHub repository.
Other Guides:Native iOS Native Android Unity Asset Package
Enable Ads in Unity
First, set the build targets and enable Unity Ads in the Services Panel.
- Open your game project, or create a new Unity project.
- Select Edit > Build Settings and set the platform to iOS or Android
- Enable Ads in the Unity Services window.
Once that's done, select Window > Services. Select an Organization from the drop down menu: Click Create.
Click Ads, and enable the SDK in your project:
Add the code
- First, declare the Unity Ads namespace in the header of your script
using UnityEngine.Advertisements;
- Then, you can display an ad by calling the following method
Advertisement.Show()
Example Code
Add a button to your scene that plays an ad, then handles status and callbacks.
Step 1: Select Game Object > UI > Button to add a Button in your scene
Step 2: Add the following script to the button:
using UnityEngine; using UnityEngine.Advertisements; public class UnityAdsExample : MonoBehaviour { public void ShowRewardedAd() { if (Advertisement.IsReady("rewardedVideo")) { var options = new ShowOptions { resultCallback = HandleShowResult }; Advertisement.Show("rewardedVideo", options); } } private void HandleShowResult(ShowResult result) { switch (result) { case ShowResult.Finished: Debug.Log("The ad was successfully shown."); // // YOUR CODE TO REWARD THE GAMER // Give coins etc. break; case ShowResult.Skipped: Debug.Log("The ad was skipped before reaching the end."); break; case ShowResult.Failed: Debug.LogError("The ad failed to be shown."); break; } } }
Then simply press the editor Play button to test the Unity Ads Button integration.
Additional examples and troubleshooting can be found in our monetization documentation.
If you have any questions, please post them to the Unity Ads forum or contact us at unityads-support@unity3d.com.
Reward Players for Watching Ads
Rewarding players can add to user engagement, resulting in higher revenue!
Typically rewarded ad implementation generally involve one or more of the following:
- In-game currency or consumables
- Extra lives at the start of the game
- Point boosts for the next round
You can reward players for completing a video ad using the HandleShowResult callback method in the example above. Be sure to check that the result is ShowResult.Finished to verify that the ad was not skipped before granting the reward.
private void HandleShowResult (ShowResult result) if (result == ShowResult.Finished) { //Add code to reward your player here! //Give coins, etc }
Manage settings in the Ads Dashboard
Log into the Unity Ads Dashboard using your UDN Account, and locate the project for your game.
Then, select a platform (iOS or Android).
From here, you can modify placements and other game-specific settings.
Additional information on placements can be found in our placements Documentation.
For additional info, please see the Unity Ads forum, Unity Ads Knowledge Base, Unity Ads Documentation, Unity Support Knowledge Base or contact us directly at unityads-support@unity3d.com.