Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Finished 2D Game. Need to know my next step with ads and everything

Discussion in 'Unity Ads & User Acquisition' started by malachiddm, Jan 27, 2015.

  1. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    It's an original idea that hasn't been done before! I'm ready to launch it on Windows phones, iOS, and Android. But I want ads to pop up between game over screens. not the huge ads just the smaller ones. but I have no idea how to do this. Is it different for each platform?

    where do I go from here? please help
     
  2. Marceta

    Marceta

    Joined:
    Aug 5, 2013
    Posts:
    177
  3. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    Which do you prefer? is one easier to use then the other or? If I Unity ads, do I have to change the code for each platform or should I be fine?
     
  4. Salazar

    Salazar

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

    I used the ads you mentioned. Pop-up an ad in the middle of screen and frame is costumisable. But that ad network pays only for installs of that ad ,most of time.

    So I integrate Unity video ads , and one other adnetwork full screen ad. I will turn full screen ads to Unity, when it will come out off beta. But if you are in US, than you can give it a try.

    Regards,
     
  5. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    So I did download Unity Ads, I have the sdk and all of that. I just truly have no idea how to make them display in my game.
     
  6. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    The package itself, like the asset folder is there but I dont know what to do next and I've read through and watched way too many things to make my head expload and everyone is doing something differerent
     
  7. Marceta

    Marceta

    Joined:
    Aug 5, 2013
    Posts:
    177
    1. Add this line in top of your script:
      Code (CSharp):
      1. using UnityEngine.Advertisements;
    2. Use this command when starting up your game:
      Code (CSharp):
      1. Advertisement.Initialize ("<YOUR GAME ID HERE>");
    3. And use this code to actually show the ad:
      Code (CSharp):
      1. if(Advertisement.isReady()){ Advertisement.Show(); }
     
  8. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    I'm sorry for being unclear in my last msg that is actually 100 percent my fault.

    I did those three steps and I get a pop up on my game saying "Here would be your ad unity (things seem to be working well"

    My question is, Why isn't it showing an actual ad there? or will it once it actually launches? The reason I'm doubting it is for two reasons.

    1. I've watched a few tutorials and all of their examples had actual ads pop up without it being launched to the store yet.?

    2. when I run the game now, all Debug things pop up on the console and I don't know why. I'm not getting any error or caution things, just the explanation point ( ! ) with a list of debug things happening.

    These may seem like stupid questions but once again this is the first game I'm officially launching and I'm not finding any info on what I should be seeing when I input that code.
     
  9. Marceta

    Marceta

    Joined:
    Aug 5, 2013
    Posts:
    177
    If you didn't created account for ad's create it here : https://unityads.unity3d.com/ then add your game id to code.
    Also ad's are working only for mobile platforms, so you will get just test message in Editor/Desktop Version. Build for example APK and install it to your mobile device, you should get real ad's
     
  10. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    Thank you so much man. One final question, do you know the code I would use to make a ad pop up after every other game over? Is there a way to do that?
     
  11. Mikenseer

    Mikenseer

    Joined:
    Jul 24, 2012
    Posts:
    74
    Code (csharp):
    1. if (AdJustPoppedUpLastTime == true)
    2. {
    3.   //Dont show ads
    4.  AdJustPoppedUpLastTime = false;
    5. }
    6. else if (AdJustPoppedUpLastTime == false)
    7. {
    8.   //SHOW ADS! Yay
    9.  AdJustPoppedUpLastTime = true;
    10. }
    Just store a bool somewhere.
     
  12. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    So I've tried a few different things and I can't get my computer to actually build my game. I've downloaded android sdk. but its asking for the root? I've looked under my C drive and programs x86 and the file isn't there. I also browsed around and a lot of others look to be asking the same question and are having the same problem. Is there a different way I could find that ?
    Also, after the game is actually built and running, what are the steps to actually publish it on Google Play and also the app store for iOS? Does Unity offer a quick way to publish?
     
  13. Mikenseer

    Mikenseer

    Joined:
    Jul 24, 2012
    Posts:
    74
    Oh my god the android SDK is the worst thing ever...

    I spent hours getting that junk to work on my Mac. Basically any time I want to use it I have to run a line in the terminal. I believe the windows solution is about the same.

    I wish I had the answer for you. My best suggestion is to keep googling. The answers I found were buried deep in stack exchange and unity answers. Not on home computer at the moment and I did not bookmark the fixes (silly me).
     
    malachiddm likes this.
  14. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    You'll be happy to know I actually already got it and yes it was a nightmare. It took probably a solid 6 hours. So it's ready to build, my next question is, how do I go about actually publishing it to the google play store? Is that under build settings too.?
    question 2, I want to instantly transfer this to a mac and download xcode and all of that so I can get it on the app store. Is it much easier to do this on that? Or will it be the same giant headache?
     
  15. Mikenseer

    Mikenseer

    Joined:
    Jul 24, 2012
    Posts:
    74
    Getting Xcode to work isn't bad. You install it, and let Unity do most of the work. Android is where the headache lies (the first time set up anyway)
     
  16. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    Okay, all I'm trying to do is actually display ads on my game when I build and run it to my android device but everything I do, nothing pops up. It's just ad free (Without) any ads. So I've been through this a million times and I'm starting to think that I'm just an idiot missing something, perhaps in my settings? Because I don't see anything wrong in my code. When I run the game on the actual PC I get a pop up saying "Here would be your ad unit (Things seem to be working properly)" but then I go to run it on my android device and nothing pops up at all????? What am I doing wrong here??

    Also yes my game ID is exactly the same in my code as it is in the unity ads monetize section where it generates the game_id for you. but here is my code.. If I'm missing something please point it out. I just don't understand why I'm getting the pop up on the laptop saying things are right and then when I build it on my phone nothing happens. Please help


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class GameController : MonoBehaviour {
    7.  
    8.     public Camera cam;
    9.     public GameObject ball;
    10.     public GameObject gameOverText;
    11.     public GameObject restartButton;
    12.     public GameObject splashScreen;
    13.     public GameObject startButton;
    14.     public HatController hatController;
    15.  
    16.     private float maxWidth;
    17.  
    18.     public bool gameOver;
    19.     private const int counterReset = 2;
    20.     public static int counterForAds = counterReset;
    21.     void Awake()
    22.     {
    23.         if (Advertisement.isSupported) {
    24.             Advertisement.allowPrecache = true;
    25.             Advertisement.Initialize ("131624602", false);
    26.         }
    27.     }
    28.     public static void resetCounter (){
    29.         counterForAds = counterReset;
    30.     }
    31.     // Use this for initialization
    32.  
    33.     void Start () {
    34.         counterForAds--;
    35.         if (counterForAds <= 0) {
    36.                         resetCounter ();
    37.                         Advertisement.Show (null, new ShowOptions {
    38.                 pause = true,
    39.                 resultCallback = ShowResult => {    if (cam == null) {
    40.                         cam = Camera.main;
    41.                     }
    42.                    
    43.                     Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
    44.                     Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
    45.                    
    46.                     maxWidth = targetWidth.x;
    47.  
    48.                 }
    49.             });
    50.                 } else {
    51.                         if (cam == null) {
    52.                                 cam = Camera.main;
    53.                         }
    54.    
    55.                         Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
    56.                         Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
    57.  
    58.                         maxWidth = targetWidth.x;
    59.                 }
    60.  
    61.     }
    62.     void FixedUpdate () {
    63.  
    64.  
    65. }
    66.     public void StartGame () {
    67.         gameOver = false;
    68.         splashScreen.SetActive (false);
    69.         startButton.SetActive (false);
    70.         hatController.ToggleControl (true);
    71.         StartCoroutine (Spawn ());
    72.         }
    73.  
    74.     IEnumerator Spawn () {
    75.         yield return new WaitForSeconds (2.0f);
    76.  
    77.         while (!gameOver) {
    78.  
    79.             Vector3 spawnPosition = new Vector3 (
    80.                         Random.Range (-maxWidth, maxWidth),
    81.                             transform.position.y,
    82.                             0.0f
    83.             );
    84.             Quaternion spawnRotation = Quaternion.identity;
    85.             Instantiate (ball, spawnPosition, spawnRotation);
    86.             yield return new WaitForSeconds (Random.Range (1.0f, 2.0f));
    87.         }
    88.         yield return new WaitForSeconds (2.0f);
    89.         gameOverText.SetActive (true);
    90.         yield return new WaitForSeconds (2.0f);
    91.         restartButton.SetActive (true);
    92.     }
    93.  
    94.  
    95. }
    96.  
     
  17. Jami_2

    Jami_2

    Joined:
    Apr 22, 2013
    Posts:
    19
    Hello,

    Sounds u have no problem with code. Is a Plugin Folder exist? Is there a Manifest in there and a Folder names unityads. And in the Android folder a Device.jar.
    Is what you need for Unity ads!

    To get your game to Playstore make your own Keystore. In Player Settings.

    I'm not on office now so can tell you the exact way.

    Any questions more?
     
  18. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44

    yes from the asset store I downloaded the sdk straight into my game. the folders are listed like, standard assets, you open that folder and you get 3 other folders
    1. Editior
    2. plugins
    3. Unity ads
    Then if you click on plugins there is only 2
    1. Android
    2. iOS
    From there, if you click on android, One more folder exist
    1. Unity ads
    The second thing within the android folder is a little java looking thing titled device just like you listed. I truly still do not under stand where I'm going wrong.
     
  19. Jami_2

    Jami_2

    Joined:
    Apr 22, 2013
    Posts:
    19
    And your AndroidManifest has correct Setup?

    Code (CSharp):
    1. <activity
    2.               android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
    3.               android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    4.               android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    5.               android:hardwareAccelerated="true" />
    6.     </application>
    7.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    8.     <uses-permission android:name="android.permission.INTERNET" />
    9.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    I can show you my way this works for me. Is for no Rewarded Ads.
    On my Logo/Splash Screen i have this.

    Code (CSharp):
    1. void Awake ()
    2.  
    3.         if (Advertisement.isSupported)
    4.         {
    5.             Advertisement.allowPrecache = true;
    6.             Advertisement.Initialize ("XXXXXX");
    7.         }
    8.  
    9.         DontDestroyOnLoad (this);
    10.     }
    11.  
    12.  
    13. }
    And a example when click a button to show a ad with counter.

    Code (CSharp):
    1. public bool isVidAds;
    2.  
    3.     private int uAdCount;
    4.  
    5.     void Start ()
    6.     {
    7.         AndroidAdMobController.instance.Init ("XXXXXXXXXXXX");
    8.      
    9.         if (PlayerPrefs.HasKey ("AdCount") == false)
    10.             uAdCount = 0;
    11.         else
    12.             uAdCount = PlayerPrefs.GetInt ("AdCount");
    13.          
    14.     }
    15.  
    16.  
    17.     void OnClick ()
    18.     {
    19.         if (!isQuit)
    20.         {
    21.             Application.LoadLevel (sceneToLoad);
    22.         }
    23.         else
    24.         {
    25.             Application.Quit ();
    26.         }
    27.      
    28.         if (isAdmob)
    29.         {
    30.          
    31.                 AndroidAdMobController.instance.StartInterstitialAd ();
    32.         }
    33.      
    34.         if (Advertisement.isSupported)
    35.         {
    36.             if (isVidAds)
    37.             {
    38.                 uAdCount += 1;
    39.                 PlayerPrefs.SetInt ("AdCount", uAdCount);
    40.              
    41.                 if (uAdCount >= 4)
    42.                 {
    43.                  
    44.                         Advertisement.Show ();
    45.                     uAdCount = 0;
    46.                     PlayerPrefs.SetInt ("AdCount", uAdCount);
    47.                 }
    48.             }
    49.         }
    50.         else
    51.         {
    52.             uAdCount += 1;
    53.             PlayerPrefs.SetInt ("AdCount", uAdCount);
    54.             if (uAdCount >= 4)
    55.             {
    56.              
    57.                     AndroidAdMobController.instance.StartInterstitialAd ();
    58.                 uAdCount = 0;
    59.                 PlayerPrefs.SetInt ("AdCount", uAdCount);
    60.             }
    61.         }
    62.     }
    63. }
     
  20. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    @malachiddm: Before calling the Show() method, you need to call the isReady() method. Whatever zone ID you pass when calling Show() also needs to be passed to isReady(). You also need to allow for enough time for Unity Ads to finish initializing and prepare ads to be shown. Try this on for size:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class GameController : MonoBehaviour {
    7.  
    8.     public Camera cam;
    9.     public GameObject ball;
    10.     public GameObject gameOverText;
    11.     public GameObject restartButton;
    12.     public GameObject splashScreen;
    13.     public GameObject startButton;
    14.     public HatController hatController;
    15.  
    16.     private float maxWidth;
    17.  
    18.     public bool gameOver;
    19.     private const int counterReset = 2;
    20.     public static int counterForAds = counterReset;
    21.  
    22.     //---------------------------
    23.     //---- UNITY ADS SECTION ----
    24.     //---------------------------
    25.     public string gameID = "131624602";
    26.     public string zoneID = null;
    27.     public float timeout = 15f;
    28.  
    29.     // Toggle this option to disable test mode
    30.     //  when Development Build is enabled.
    31.     public bool disableTestMode;
    32.  
    33.     private float _startTime = 0f;
    34.     private float _yieldTime = 1f;
    35.  
    36.     void Awake ()
    37.     {
    38.         bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
    39.         Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
    40.                                 gameID, enableTestMode ? "enabled" : "disabled"));
    41.         Advertisement.Initialize(gameID,enableTestMode);
    42.     }
    43.  
    44.     private IEnumerator ShowAdWhenReady ()
    45.     {
    46.         // Set zoneID to null if string is empty.
    47.         //  When zoneID value is null, the default zone is used.
    48.         if (string.IsNullOrEmpty(zoneID)) zoneID = null;
    49.      
    50.         // Check to see if Unity Ads is initialized.
    51.         //  If not, wait a second before trying again.
    52.         do yield return new WaitForSeconds(_yieldTime);
    53.         while (!Advertisement.isInitialized);
    54.      
    55.         Debug.Log("Unity Ads has finished initializing. Waiting for ads to be ready...");
    56.      
    57.         // Set a start time for the timeout.
    58.         _startTime = Time.timeSinceLevelLoad;
    59.      
    60.         // Check to see if Unity Ads are available and ready to be shown.
    61.         //  If not, wait a second before trying again.
    62.         while (!Advertisement.isReady(zoneID))
    63.         {
    64.             if (Time.timeSinceLevelLoad - _startTime > timeout)
    65.             {
    66.                 Debug.LogWarning("The process for showing ads on load has timed out. " +
    67.                                  "Ad not shown.");
    68.              
    69.                 // Break out of both this loop and the Start method; Unity Ads will not
    70.                 //  be shown on load since the wait time exceeded the time limit.
    71.                 yield break;
    72.             }
    73.          
    74.             yield return new WaitForSeconds(_yieldTime);
    75.         }
    76.      
    77.         Debug.Log("Ads are available and ready. Showing ad now...");
    78.  
    79.         ShowOptions options = new ShowOptions();
    80.         options.pause = true;
    81.         options.resultCallback = HandleShowResult;
    82.      
    83.         // Show ad after Unity Ads finishes initializing and ads are ready to show.
    84.         Advertisement.Show(zoneID,options);
    85.     }
    86.  
    87.     private void HandleShowResult (ShowResult result)
    88.     {
    89.         switch (result)
    90.         {
    91.         case ShowResult.Finished:
    92.             Debug.Log("The ad was successfully shown.");
    93.             break;
    94.         case ShowResult.Skipped:
    95.             Debug.Log("The ad was skipped before reaching the end.");
    96.             break;
    97.         case ShowResult.Failed:
    98.             Debug.LogError("The ad failed to be shown.");
    99.             break;
    100.         }
    101.  
    102.         SetMaxWidth();
    103.         ResetCounter();
    104.     }
    105.     //-------------------------------
    106.     //--- [END] UNITY ADS SECTION ---
    107.     //-------------------------------
    108.  
    109.     private void SetMaxWidth ()
    110.     {
    111.         if (cam == null) cam = Camera.main;
    112.      
    113.         Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
    114.         Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
    115.      
    116.         maxWidth = targetWidth.x;
    117.     }
    118.  
    119.     public static void ResetCounter ()
    120.     {
    121.         counterForAds = counterReset;
    122.         PlayerPrefs.SetInt("adCounter",counterReset);
    123.     }
    124.  
    125.     void Start ()
    126.     {
    127.         if (PlayerPrefs.HasKey("adCounter"))
    128.             counterForAds = PlayerPrefs.GetInt("adCounter");
    129.         else ResetCounter();
    130.  
    131.         if (counterForAds <= 0) {
    132.             Debug.Log("Showing ad now...");
    133.             StartCoroutine(ShowAdWhenReady());
    134.             // Use the HandleShowResult method to reset the counter after the ad is shown.
    135.         } else {
    136.             Debug.Log(string.Format("Showing ad in {0} more turns.",counterForAds));
    137.             SetMaxWidth();
    138.         }
    139.  
    140.         PlayerPrefs.SetInt("adCounter",--counterForAds);
    141.     }
    142.  
    143.     public void StartGame ()
    144.     {
    145.         gameOver = false;
    146.         splashScreen.SetActive (false);
    147.         startButton.SetActive (false);
    148.         hatController.ToggleControl (true);
    149.         StartCoroutine (Spawn ());
    150.     }
    151.  
    152.     IEnumerator Spawn ()
    153.     {
    154.         yield return new WaitForSeconds (2.0f);
    155.      
    156.         while (!gameOver) {
    157.          
    158.             Vector3 spawnPosition = new Vector3 (
    159.                 Random.Range (-maxWidth, maxWidth),
    160.                 transform.position.y,
    161.                 0.0f
    162.                 );
    163.             Quaternion spawnRotation = Quaternion.identity;
    164.             Instantiate (ball, spawnPosition, spawnRotation);
    165.             yield return new WaitForSeconds (Random.Range (1.0f, 2.0f));
    166.         }
    167.         yield return new WaitForSeconds (2.0f);
    168.         gameOverText.SetActive (true);
    169.         yield return new WaitForSeconds (2.0f);
    170.         restartButton.SetActive (true);
    171.     }
    172. }
    EDIT: Made some additional changes to the ResetCounter() and Start() logic to relying on a PlayerPrefs key/value pair rather than a public static variable. Also, move ResetCounter() to the callback method so that it's called only after the ad is shown.
     
    Last edited: Feb 5, 2015
    arlefreak and adam_mehman like this.
  21. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44

    Hey man I had school all week just getting back to this and same thing. It's working fine in unity and I still get the pop up saying. Things seem to be working right. But when I build and run it on the phone. I still don't have anything pop up. I also sent my apk to someone else just for him to try it, thinking maybe its my network and nothing still. I've read into too and others are saying it's only working on android 5.0 for them? anything on that? I have the next two days off so Please get back to me asap :D
     
  22. malachiddm

    malachiddm

    Joined:
    Dec 30, 2014
    Posts:
    44
    I'm also going to try to build it on iOS here in a sec just to see if that changes things.