Skip to content

Unity Rewarded Video Delegates

Mert Celik edited this page Jan 8, 2019 · 4 revisions

Please refer to RewardedVideoSampleScript.cs in our Unity plugin for complete implementation.

1 . Set the delegates

After getting the AMRewarded instance, add the delegates with the code below:

// Assuming your AMRewarded instance is named "rewarded"
rewarded.OnAdDidLoad += this.HandleOnAdDidLoad;
rewarded.OnAdDidFailToLoad += this.HandleOnAdDidFailToLoad;
rewarded.OnAdDidShow += this.HandleOnAdDidShow;
rewarded.OnAdDidClose += this.HandleOnAdDidClose;
rewarded.OnAdDidClick += this.HandleOnAdDidClick;

2 . Implement the delegate methods

After setting the delegates, add the delegates methods as shown in example below:

private void HandleOnAdDidLoad(object sender, EventArgs args)
{
  this.statusLabel.text = "Rewarded loaded.";
}

private void HandleOnAdDidFailToLoad(object sender, AMFailedToLoadEventArgs args)
{
  this.statusLabel.text = "Rewarded failed to load.";
}

private void HandleOnAdDidClick(object sender, EventArgs args)
{
  this.statusLabel.text = "Rewarded clicked.";
}

private void HandleOnAdDidShow(object sender, EventArgs args)
{
  this.statusLabel.text = "Rewarded shown.";
}

private void HandleOnAdDidClose(object sender, EventArgs args)
{
  this.statusLabel.text = "Rewarded closed.";
}

ANDROID ONLY: Callbacks are not returned on Unity thread, so if you need to interact with API functions that requires Unity thread to work, you will need to handle it different, otherwise your app might fail to call that API functions. You can check example implementation in our RewardedSampleScript.cs. Please check the UnityThread class in our plugin for more details.

Clone this wiki locally