I am using Unity ads and it seems I can only get the ads to run in the Update() function, this keeps playing over and over and doesn’t allow enough time between ads for me to carry on with the game.
I want to play it once using the start function but then it doesn’t play at all, I also tried wrapping it in a loop like so which also doesn’t work, anyone have any ideas?
void Update()
{
if (adHasRun == false)
{
Advertisement.Initialize("myNum");
if (Advertisement.isReady()) { Advertisement.Show(); }
}
}
Start() happens when the GameObject is first created. That might mean that the ad you want hasn’t been fetched from the server. So, I guess you can initialise the ad in Start(), and play it in Update() once it’s ready. I guess you are doing this, or trying to do this. Once the ad has shown, set adHasRun to true and it shouldn’t play again.
From a users point of view do you really want to show them an ad as the first thing they do?
@Graham Dunnett, thanks for the input, there was still an issue with the ad playing but I’m assuimg that was because I was setting adHasRun in the Update function which was obviously (now that I think about it :P) being set to true before the ad was played. This is my new code:
void Start ()
{
Advertisement.Initialize("num");
}
void Update()
{
if (adHasRun == false)
{
if (Advertisement.isReady()) { Advertisement.Show(); }
if(Advertisement.isShowing)
{
adHasRun = true;
}
}
}