Search Unity

Where to place scripts exactly?

Discussion in 'Unity Ads & User Acquisition' started by SnStarr, Jan 23, 2015.

  1. SnStarr

    SnStarr

    Joined:
    Mar 6, 2014
    Posts:
    23
    In the Unity Ads Documentation it say to put Using UnityEngine.Advertisements; in your script. Which script. The main script in my game? A new script attached to an empty game object? Do I just add it to the scripts that come with the unity ads package? Documentation is not too clear on this.
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    The example script here:

    https://unityads.unity3d.com/help/D...shers/Integration-Guide-for-Unity-Asset-Store

    shows you pretty much everything you need to know. Add that script to your project, and make a new empty GameObject that just has that script on. When you press the play button the buttons in that script should appear. You're now using Unity Ads.

    When you add a "using" into a script, you are giving that script the ability to use the functions/variables that that assembly adds. So, you need to add the using into any script where you want to call into the Advertisements code.
     
    SnStarr likes this.
  3. SnStarr

    SnStarr

    Joined:
    Mar 6, 2014
    Posts:
    23
    Okay I read that and I understand it. However one last question. Do I need the Game Object with that script on it in each scene, or just in any scene, and it will generate ads no matter which scene the user is in? Thanks for all the help.
     
  4. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello,
    Yes you need a gameobject empty or not, attach your script to that object. You can use initialize method only once per game session. So its a good practice to initialize ad network when game first starts, or initialize when network connection is on(it mentioned somewhere in this forum). You can keep this gameobject in every scene and use it something like your ad network manager script. Or you can divide initialization part if you dont keep.
    Keep digging.

    Regards,
     
    SnStarr likes this.
  5. SnStarr

    SnStarr

    Joined:
    Mar 6, 2014
    Posts:
    23
    So I can also place something like DontDestroyOnLoad, etc, in the script and have the Game Object instantiate itself per scene? Or I'll just have it in the main scene and initialize it on runtime? Thanks a alot.
     
  6. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello,
    If you use DontDestroyonLoad , you dont need to create another instatiate.

    Regards,
     
  7. SnStarr

    SnStarr

    Joined:
    Mar 6, 2014
    Posts:
    23
    Right. I got it. Thanks a lot for all the help.
     
  8. SnStarr

    SnStarr

    Joined:
    Mar 6, 2014
    Posts:
    23
    I placed the script shown on the link above, as described by everyone, but its giving me an error for unexpected symbol of "<" on the line Advertisement.Initialize (<YOUR GAME ID HERE>); If I remove the <> it says
    No overload for method `Initialize' takes `1' arguments If I remove the () instead it says Unexpected symbol ";"

    Any ideas what I'm missing?
     
  9. mgnr

    mgnr

    Joined:
    Mar 3, 2014
    Posts:
    1
    Use code:
    Advertisement.Initialize ("12345");

    Replace 12345 with your GAME ID. More details here: https://www.youtube.com/watch?v=8FVVDa6eGfw#t=235 (from 3:53).
     
  10. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Salazar likes this.
  11. ShazBang

    ShazBang

    Joined:
    Nov 3, 2014
    Posts:
    21
    Hey all, I'm getting an error: No overload for method `Initialize' takes `1' arguments

    What could that mean? I'm not too good with code, also, when you said this, Graham, what did you mean?

    "When you add a "using" into a script, you are giving that script the ability to use the functions/variables that that assembly adds. So, you need to add the using into any script where you want to call into the Advertisements code."

    So I would need to add some sort of "using" line into the script? Why isn't there one on there already? :confused:
     
  12. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello,

    using UnityEngine.Advertisements;

    You should use it in top of your C# code. You can search on web c# libraries and usage.

    Graham gives a link that has sample code, and you can search this forum for more sample codes.

    No pain no gain =)

    Regards,
     
  13. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Check out this demo script. It's a fully commented version of the one available in the Unity Ads docs, which should help answer some of the questions you have. Let me know if you're still fuzzy about any part of the integration.
     
    Graham-Dunnett likes this.
  14. ClockworkWolf

    ClockworkWolf

    Joined:
    Sep 12, 2013
    Posts:
    55
    Feedback: Using the pdf included in the asset store unityads package, I did not realize the gameid needs to be a string parameter.

    Thanks, mgnr, for the hint above!
     
    unity-nikkolai likes this.