1. Integrate Admob Unity Base, Found here .
2. Vungle requires all placements to be passed to initialize as of SDK 5.x.Because of this you will need a special Admob Adapter Unity Package. After you import the adapter package, you should find Vungle SDK has already been imported.
3. Go Assets>Play Services Resolver>Android Resolver>Resolve
4. Code you need below:
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using GoogleMobileAds.Api.Mediation.Vungle;
public class playAd : MonoBehaviour {
RewardBasedVideoAd rewardBasedVideo;
// Use this for initialization
void Start () {
RequestRewarded ();
}
// Update is called once per frame
void Update () {
}
public void play(){
ShowRewarded ();
}
private void RequestRewarded()
{
#if UNITY_ANDROID
string adUnitId = "Your Admob Android Unit ID";
#elif UNITY_IPHONE
string adUnitId = "Your Admob iOS Unit ID";
#else
string adUnitId = "unexpected_platform";
#endif
//Create a new empty VRVME Object, required to add additional parameters, rewarded only
VungleRewardedVideoMediationExtras extras = new VungleRewardedVideoMediationExtras();
// Please input all your placements here under the Vungle app id.
// **Please also input the placement you want to play on admob dashboard.**
extras.SetAllPlacements(new string[] { "Your Vungle Placement ID", "Your Vungle Placement ID"});
AdRequest request = new AdRequest.Builder().AddMediationExtras(extras).Build();
//Initialize a Rewarded Video Ad
rewardBasedVideo = RewardBasedVideoAd.Instance;
//Loads an ad with the above parameters
rewardBasedVideo.LoadAd(request, adUnitId);
}
private void ShowRewarded()
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
}
}
}
网友评论