By passing in a ShowOptions object to Advertisement.Show(), you can specify a callback method which is called when ads is closed. E.g.
using UnityEngine;
using UnityEngine.Advertisements;
public class UnityAdsExample : MonoBehaviour
{
public void ShowRewardedAd()
{
if (Advertisement.IsReady("rewardedVideoZone"))
{
var options = new ShowOptions { resultCallback = HandleShowResult };
Advertisement.Show("rewardedVideoZone", 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;
}
}
}
How are you able to have game continuing while ad is being shown? Game should be paused in that situation…
Hi @rasmus-unity i would like to know if there is a way to detect the close button has been clicked?
so i can play a reward animation when the user closes the ad after it has finished playing, is there a way?
Kinda like how crossy roads does it, the coin animation plays after you have watched the video and then press the close button as it doesnt autocloses itself
Hope I understand you correctly, but that is what the HandleShowResult() method in above does, right?
Again, if you check for result==ShowResult.Finished like in above code, this is when you know that the user watched the ad to the end, and you can give reward.
As said, hope I understood your question correct. Feel free to follow up.
Yes this happens, but i need to know when the user clicks the close ad button top righ corner.
So when they get back to the game, i play an animation, if i play the animation while the result event is fired the user wont be able to see it, unless they close the unity ad video, right?
i haven’t tested, i’m assuming that it will try to play the animation while the video is still visible and the game is paused.
I’m just trying to cover bases, so i don’t have to come back and ask again :C.
Thanks for the assistance, i will come back and post my results.
Hi, What should I do if I need an event when ad closed button is pressed by user…In my game, I want to do a gameplay resumes when a user closes the ad window…I have tried on finished event but if closed button is pressed after some time of ad finished it looks like all messed up as I think ad finished event called when an ad is completed but not on a closed button.
Hi @rasmus-unity, I also need an event when ad closed button is pressed by user in my game, and I also try on finished event, but it is trigger before player press closed button. Because I run a method which will ignore time scale=0 pause, if I put it in finished event, it will run before player press closed button.
Guys I have also small problem, when I open my UI Shop and when user clicks to watch reward video, after it’s finished rewarding is done, but when you click CLOSE BUTTON unity closes my shop …
It closes shop because My Exit button from shop is on same place as Ads Close Button and click goes through…
I can disable exit button when user starts watching video and enable it after video but how do I detect CLOSE Ads was clicked ?
Great solution.
But I have a problem. Where is “exitButton”? Where is initialized? Where can I find it?
Even with ASD opened does in not appear in the Unity Hierarchy.
I need to listen her click (to put time scale = 1)…
I have this issue too. I have a particle system I fire off when I get the OnUnityAdsShowComplete() event. But it always fires before the user has closed the rewarded ad window. I can tell because if I set the particle system to loop I can see it running. Is there a way to wait until the ad window is closed?