Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity Ads keep playing after closing a ad?

Discussion in 'Unity Ads & User Acquisition' started by Torca, Dec 2, 2014.

  1. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
    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
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello, Torca

    You shouldnt use
    Code (CSharp):
    1. Advertisement.Show();
    with Update function.

    Code (CSharp):
    1. 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.
     
    unity-nikkolai likes this.
  3. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
     
  4. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
    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?
     
  5. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello Torca,

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

    Lets go with your script;
    Code (CSharp):
    1. using UnityEngine.Advertisements;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Ad2 : MonoBehaviour {
    6.  
    7. // Use this for initialization
    8. void Start () {Advertisement.Initialize ("ID#");
    9.  
    10. }
    11.  
    12. // Update is called once per frame
    13. void Update ()
    14. {
    15. if (Input.GetKey ("escape"))
    16. {
    17. if(Advertisement.isReady())
    18.     {
    19. Advertisement.Show();
    20.     }
    21. }
    22. }
    23. }
     
    unity-nikkolai likes this.
  6. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
    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?
     
    Last edited: Dec 4, 2014
  7. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    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,
     
    unity-nikkolai likes this.
  8. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
    I will give it a try.
    Thanks for all your help Salazar.

    Cheers
    Thor
     
  9. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    540
    Salazar likes this.
  10. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
    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?
     
  11. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    540
    Would you mind listing the compiler errors you get?
     
  12. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
    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?
     
  13. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello Torca;

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

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. 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
     
  14. MrTiger

    MrTiger

    Joined:
    Jan 9, 2014
    Posts:
    29
    Hi Torca ,
    Try importing the unity ads package from asset store . hope it will help you .
     
  15. Torca

    Torca

    Joined:
    May 24, 2013
    Posts:
    10
  16. MrTiger

    MrTiger

    Joined:
    Jan 9, 2014
    Posts:
    29
    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 ...
     
    Salazar likes this.
  17. calebebrim

    calebebrim

    Joined:
    May 13, 2015
    Posts:
    2
    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.
     
    keeta2002 likes this.
  18. keeta2002

    keeta2002

    Joined:
    Jul 18, 2015
    Posts:
    1
    same here need help cant find answer
     
  19. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    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,