Unity Ad shows twice?
Hi i have a game that displays an add when has gotten over 10 points and dies. a weird bug appeared. After getting 10 points and dying the ad will display like normally and then after closing it, another ad will appear and it will play, but then everything works like it suppose to work.
My script trigger. if (dead) { if (deathCooldown <= 0) { if (Score.score >= 10) { ShowAd(); }
definition
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show("rewardedVideo", new ShowOptions(){resultCallback = HandleAdResult});
}
}
private void HandleAdResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Application.LoadLevel(Application.loadedLevel);
break;
case ShowResult.Skipped:
Application.LoadLevel(Application.loadedLevel);
break;
case ShowResult.Failed:
Debug.Log("Failed");
break;
}
}
are you calling the ShowAd function twice possibly? is it called when both death conditions are met,so
if(deathCoolDown <= 0 && Score.score >= 10)
ShowAd();
Answer by Eemil_Ahonen · Dec 10, 2016 at 12:12 PM
Fixed it myself Just added AdShown Bool that was false.
if (dead) { if (deathCooldown <= 0) { if (Score.score >= 10 && AdShown == false) { ShowAd(); }
Answer by Eemil_Ahonen · Dec 04, 2016 at 06:37 PM
@Paricus im using that if(deathcooldown..... for other things aswell. and yes its called when player is dead, then it checks the deathcooldown and if it's 0 it checks if the score was over 10. if it wasn't ad will not show.
put a debug.log in your ShowAd() function. if you get the same log twice, the function is being called twice after death, which might explain the problem
@Paricus the problem doesn't appear on the unity. It shows the ad once and everything works correctly.
have you got two ads under the same id by any chance, if not i'd recommend creating a test project with just the ad functionality and seeing if you have the same problem. if so its either a problem with unity ads or the script
@Paricus the thing is under void update so that is the issue. tried putting Application.LoadLevel(Application.loadedLevel); under case ShowResult.Failed: but it still shows 2 ads because it's not fast enough. there should be a thing that checks if the ad is already played so it won't show another but i don't know how.
Answer by unity_17194192410E90131A21 · Sep 22, 2021 at 06:59 PM
I found a good solution: just add in your RewardedVideo script this:
private void OnDestroy()
{
Advertisement.RemoveListener(this);
}
Another way it didn't disappear was in the next scene. Or the opposite - use one AdManager and add to it
DontDestroyOnLoad(this);
Your answer
Follow this Question
Related Questions
need help with Heyzap 0 Answers
Unity Ads 0$ 1 Answer
Unity switches scenes when Ad is closed. 0 Answers
HeyZap xcode build error symbol(s) not found for architecture arm64 0 Answers
Unity ads only dummy on phone live 0 Answers