Unity Ads keep playing after closing a ad?

Hi

I added the script from “Getting started it’s that simple” from the unity asset store plugin.

using UnityEngine.Advertisements;
using UnityEngine;
using System.Collections;

public class Ad2 : MonoBehaviour {

// Use this for initialization
void Start () {Advertisement.Initialize (“ID#”);

}

// Update is called once per frame
void Update () {if(Advertisement.isReady()){ Advertisement.Show(); }

}
}

When I press the ad close button the ads keep playing one after another with no pause between them?

Thanks
Thor

Hello, Torca

You shouldnt use Advertisement.Show(); with Update function.

Advertisement.isReady() method is “true” as soon as Advertisement is Ready. An your if statement is always true. You are trying to show your ad in every frame.

1 Like

Hi Salazar

I am a graphics guy not a coder I just copied the code from the unity ad site.

Are you saying I should remove the Advertisement.Show(); and place somewhere else?

Hello Torca,

Yes you should remove Advertisement.Show(); from your Update method, or dont use directly in update method.

Lets go with your script;

using UnityEngine.Advertisements;
using UnityEngine;
using System.Collections;

public class Ad2 : MonoBehaviour {

// Use this for initialization
void Start () {Advertisement.Initialize ("ID#");

}

// Update is called once per frame
void Update ()
{
if (Input.GetKey ("escape"))
{
if(Advertisement.isReady())
    {
Advertisement.Show();
    }
}
}
}
1 Like

Hi Salazar

I copied the code and saved it as .cs press esc key and the ad spot (Blue box) shows.
I sent through xcode to my ipad it looks like it’s trying to do something but does not show?
Maybe the ads are not currently being served?

Hi Torca,

Change Input.GetKey(“escape”) with Input.anyKeyDown it may solve your problem for now, I dont know what is mapped for escape in ipad.
I am not a professional developer, I am just trying to show an example. You should search for good practices for using Unity3d it self.
I recommend you to dive into Unity.com and follow learning paths…

Thanks,

1 Like

I will give it a try.
Thanks for all your help Salazar.

Cheers
Thor

If you’re looking for a few additional implementation examples, check out this project:
https://github.com/wcoastsands/unity-ads-demo

1 Like

I downloaded the demo it won’t play I get a compiler errors message.
Wouldn’t it just be easier to post a complete working script on the getting started page?

Would you mind listing the compiler errors you get?

Hi Nikkolai

Here is the demo error.

Assets/DemoApp/Scripts/level/LevelSceneController.cs(3,19): error CS0234: The type or namespace name Advertisements' does not exist in the namespace UnityEngine’. Are you missing an assembly reference?

Hello Torca;

Did you add UnityEngine.Advertisements; library to your LevelSceneController.cs .
You must add libraries that you are using it in your code…

using System;
using UnityEngine;
using UnityEngine.Advertisements;

You should write these on top of your script, and now on you can use UnityEngine.Advertisements 's functions in your script.

Thanks

Hi Torca ,
Try importing the unity ads package from asset store . hope it will help you .

Did already. The unity ads work with the code from
http://unityads.unity3d.com/help/Documentation%20for%20Publishers/GettingStarted
it’s just that when i close the ad another plays close it and other plays etc. you can’t get back to the game.

I think it’s coz of Advertisement.Show() is called whenever Advertisement.isReady() = true so you need to call Advertisement.Show() when a button is pressed or some action is done like when game over , player leaving etc …

1 Like

I couldn’t use the following line on monodevelop

using UnityEngine.Advertisements;

it accuse the following error:
The type or namespace name Advertisements' does not exist in the namespace UnityEngine’. Are you missing an assembly reference

I can’t compile my game.

I’ve imported the UnityAds from asset store.

1 Like

same here need help cant find answer

Hello @keeta2002 ,

Sounds like a unity ads package installation problem. Could you please, try to remove all unity ads folders from your asset folder and re install the latest unity-ads package from asset store.Please let us know if it changes anything.

Regards,