I’m trying to implement Unity Rewarded video ads. I watched the video by Mike Geig, and he mentions that it would be a good approach to pass in a delegate to be called by the Advertisement.Show callback method, which makes sense to me. Unfortunately I don’t have much experience with delegates and I can’t understand the error this throws. I’m able to pass in a delegate method from the same “AdShower” class, but not from my external class.
The error is: Cannot implicitly convert type ‘AdShower.ResultDelegate’ to ‘System.Action< UnityEngine.Advertisements.ShowResult>’
using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;
public class AdShower : MonoBehaviour
{
private string gameID = "";
private string rewardedPlacementID = "rewardedVideo";
public delegate void ResultDelegate (ShowResult result);
void Awake()
{
Advertisement.Initialize (gameID, true);
}
public bool RewardedAdIsReady()
{
return Advertisement.IsReady (rewardedPlacementID);
}
public void TryShowRewardedAd(ResultDelegate theDelegate)
{
ShowOptions options = new ShowOptions ();
options.resultCallback = theDelegate;
if (Advertisement.IsReady (rewardedPlacementID))
Advertisement.Show (rewardedPlacementID, options);
}
}
Here is a snippet from the other class I want to call the “TryShowRewardedAd” Method:
public void VideoContinueButtonPressed()
{
// already confirmed a video is ready
r.adShower.TryShowRewardedAd(HandleVideoResult);
}
private void HandleVideoResult(ShowResult result)
{
if (result == ShowResult.Finished)
{
Continue();
}
}