How to use unity rewarded ads?
I have trouble using the unity ads reward system. I want to make a game where if I press a button an ad will show and the player will get some points. I added at the OnClick parameter the function Ads.ShowRewardedAd. This is my script:
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;
}
}
}
Answer by unityplayer1989 · Jul 15, 2017 at 03:50 AM
Download Admob Unity3d Plugin https://github.com/unity-plugins/Unity-Admob
Installation Admob Unity
Open your project in the Unity editor. Navigate to Assets -> Import Package -> Custom Package. Select the AdmobUnityPlugin.unitypackage file. Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.
Init Admob Unity Plugin
Create A C# script ,drag the script to a object on scene , add the follow code in the script file
using admob;
Admob.Instance().initAdmob("admob banner id", "admob interstitial id");//admob id with format ca-app-pub-279xxxxxxxx/xxxxxxxx
//Admob.Instance().initAdmob("ca-app-pub-3940256099942544/2934735716", "ca-app-pub-3940256099942544/4411468910");
Here is the minimal code to create an admob video.
Admob.Instance().loadRewardedVideo("ca-app-pub-3940256099942544/1712485313");
Video need to be explicitly shown at an appropriate stopping point in your app, check that the video is ready before showing it:
if (Admob.Instance().isRewardedVideoReady()) {
Admob.Instance().showRewardedVideo();
}
Your answer
Follow this Question
Related Questions
Auto Set vs Manual Decrease (How to do both?) 1 Answer
How can I fix this animation flick 0 Answers
change game character/controller when inside box - RFPSP 1 Answer
Does anyone know why transform.position isn't working? (See details) 1 Answer
How can i make sure the script will work only on the attached object ? 1 Answer