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

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

You can use google admob : Google AdMob - Earn More With Mobile App Monetization , Mobile Ads SDK  |  Google for Developers
or unity : https://unityads.unity3d.com/

1 Like

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?

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,

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.

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

  • Add this line in top of your script:using UnityEngine.Advertisements;
  • Use this command when starting up your game:Advertisement.Initialize ("<YOUR GAME ID HERE>");
  • And use this code to actually show the ad:if(Advertisement.isReady()){ Advertisement.Show(); }

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.

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

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?

if (AdJustPoppedUpLastTime == true)
{
  //Dont show ads
 AdJustPoppedUpLastTime = false;
}
else if (AdJustPoppedUpLastTime == false)
{
  //SHOW ADS! Yay
 AdJustPoppedUpLastTime = true;
}

Just store a bool somewhere.

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?

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).

1 Like

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?

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)

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

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

public class GameController : MonoBehaviour {

    public Camera cam;
    public GameObject ball;
    public GameObject gameOverText;
    public GameObject restartButton;
    public GameObject splashScreen;
    public GameObject startButton;
    public HatController hatController;

    private float maxWidth;

    public bool gameOver;
    private const int counterReset = 2;
    public static int counterForAds = counterReset;
    void Awake()
    {
        if (Advertisement.isSupported) {
            Advertisement.allowPrecache = true;
            Advertisement.Initialize ("131624602", false);
        }
    }
    public static void resetCounter (){
        counterForAds = counterReset;
    }
    // Use this for initialization

    void Start () {
        counterForAds--;
        if (counterForAds <= 0) {
                        resetCounter ();
                        Advertisement.Show (null, new ShowOptions {
                pause = true,
                resultCallback = ShowResult => {    if (cam == null) {
                        cam = Camera.main;
                    }
                   
                    Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
                    Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
                   
                    maxWidth = targetWidth.x;

                }
            });
                } else {
                        if (cam == null) {
                                cam = Camera.main;
                        }
   
                        Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
                        Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);

                        maxWidth = targetWidth.x;
                }

    }
    void FixedUpdate () {


}
    public void StartGame () {
        gameOver = false;
        splashScreen.SetActive (false);
        startButton.SetActive (false);
        hatController.ToggleControl (true);
        StartCoroutine (Spawn ());
        }

    IEnumerator Spawn () {
        yield return new WaitForSeconds (2.0f);

        while (!gameOver) {

            Vector3 spawnPosition = new Vector3 (
                        Random.Range (-maxWidth, maxWidth),
                            transform.position.y,
                            0.0f
            );
            Quaternion spawnRotation = Quaternion.identity;
            Instantiate (ball, spawnPosition, spawnRotation);
            yield return new WaitForSeconds (Random.Range (1.0f, 2.0f));
        }
        yield return new WaitForSeconds (2.0f);
        gameOverText.SetActive (true);
        yield return new WaitForSeconds (2.0f);
        restartButton.SetActive (true);
    }


}

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?

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
  4. Android
  5. iOS
    From there, if you click on android, One more folder exist
  6. 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.

And your AndroidManifest has correct Setup?

<activity
              android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
              android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
              android:hardwareAccelerated="true" />
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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.

void Awake ()
 
        if (Advertisement.isSupported)
        {
            Advertisement.allowPrecache = true;
            Advertisement.Initialize ("XXXXXX");
        }
 
        DontDestroyOnLoad (this);
    }
 
 
}

And a example when click a button to show a ad with counter.

public bool isVidAds;
 
    private int uAdCount;
  
    void Start ()
    {
        AndroidAdMobController.instance.Init ("XXXXXXXXXXXX");
     
        if (PlayerPrefs.HasKey ("AdCount") == false)
            uAdCount = 0;
        else
            uAdCount = PlayerPrefs.GetInt ("AdCount");
         
    }
 
 
    void OnClick ()
    {
        if (!isQuit)
        {
            Application.LoadLevel (sceneToLoad);
        }
        else
        {
            Application.Quit ();
        }
     
        if (isAdmob)
        {
         
                AndroidAdMobController.instance.StartInterstitialAd ();
        }
     
        if (Advertisement.isSupported)
        {
            if (isVidAds)
            {
                uAdCount += 1;
                PlayerPrefs.SetInt ("AdCount", uAdCount);
             
                if (uAdCount >= 4)
                {
                 
                        Advertisement.Show ();
                    uAdCount = 0;
                    PlayerPrefs.SetInt ("AdCount", uAdCount);
                }
            }
        }
        else
        {
            uAdCount += 1;
            PlayerPrefs.SetInt ("AdCount", uAdCount);
            if (uAdCount >= 4)
            {
             
                    AndroidAdMobController.instance.StartInterstitialAd ();
                uAdCount = 0;
                PlayerPrefs.SetInt ("AdCount", uAdCount);
            }
        }
    }
}

@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:

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

public class GameController : MonoBehaviour {
  
    public Camera cam;
    public GameObject ball;
    public GameObject gameOverText;
    public GameObject restartButton;
    public GameObject splashScreen;
    public GameObject startButton;
    public HatController hatController;
  
    private float maxWidth;
  
    public bool gameOver;
    private const int counterReset = 2;
    public static int counterForAds = counterReset;

    //---------------------------
    //---- UNITY ADS SECTION ----
    //---------------------------
    public string gameID = "131624602";
    public string zoneID = null;
    public float timeout = 15f;

    // Toggle this option to disable test mode
    //  when Development Build is enabled.
    public bool disableTestMode;

    private float _startTime = 0f;
    private float _yieldTime = 1f;

    void Awake ()
    {
        bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
        Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
                                gameID, enableTestMode ? "enabled" : "disabled"));
        Advertisement.Initialize(gameID,enableTestMode);
    }

    private IEnumerator ShowAdWhenReady ()
    {
        // Set zoneID to null if string is empty.
        //  When zoneID value is null, the default zone is used.
        if (string.IsNullOrEmpty(zoneID)) zoneID = null;
      
        // Check to see if Unity Ads is initialized.
        //  If not, wait a second before trying again.
        do yield return new WaitForSeconds(_yieldTime);
        while (!Advertisement.isInitialized);
      
        Debug.Log("Unity Ads has finished initializing. Waiting for ads to be ready...");
      
        // Set a start time for the timeout.
        _startTime = Time.timeSinceLevelLoad;
      
        // Check to see if Unity Ads are available and ready to be shown.
        //  If not, wait a second before trying again.
        while (!Advertisement.isReady(zoneID))
        {
            if (Time.timeSinceLevelLoad - _startTime > timeout)
            {
                Debug.LogWarning("The process for showing ads on load has timed out. " +
                                 "Ad not shown.");
              
                // Break out of both this loop and the Start method; Unity Ads will not
                //  be shown on load since the wait time exceeded the time limit.
                yield break;
            }
          
            yield return new WaitForSeconds(_yieldTime);
        }
      
        Debug.Log("Ads are available and ready. Showing ad now...");

        ShowOptions options = new ShowOptions();
        options.pause = true;
        options.resultCallback = HandleShowResult;
      
        // Show ad after Unity Ads finishes initializing and ads are ready to show.
        Advertisement.Show(zoneID,options);
    }

    private void HandleShowResult (ShowResult result)
    {
        switch (result)
        {
        case ShowResult.Finished:
            Debug.Log("The ad was successfully shown.");
            break;
        case ShowResult.Skipped:
            Debug.Log("The ad was skipped before reaching the end.");
            break;
        case ShowResult.Failed:
            Debug.LogError("The ad failed to be shown.");
            break;
        }

        SetMaxWidth();
        ResetCounter();
    }
    //-------------------------------
    //--- [END] UNITY ADS SECTION ---
    //-------------------------------

    private void SetMaxWidth ()
    {
        if (cam == null) cam = Camera.main;
      
        Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
        Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
      
        maxWidth = targetWidth.x;
    }

    public static void ResetCounter ()
    {
        counterForAds = counterReset;
        PlayerPrefs.SetInt("adCounter",counterReset);
    }
  
    void Start ()
    {
        if (PlayerPrefs.HasKey("adCounter"))
            counterForAds = PlayerPrefs.GetInt("adCounter");
        else ResetCounter();

        if (counterForAds <= 0) {
            Debug.Log("Showing ad now...");
            StartCoroutine(ShowAdWhenReady());
            // Use the HandleShowResult method to reset the counter after the ad is shown.
        } else {
            Debug.Log(string.Format("Showing ad in {0} more turns.",counterForAds));
            SetMaxWidth();
        }

        PlayerPrefs.SetInt("adCounter",--counterForAds);
    }
  
    public void StartGame ()
    {
        gameOver = false;
        splashScreen.SetActive (false);
        startButton.SetActive (false);
        hatController.ToggleControl (true);
        StartCoroutine (Spawn ());
    }
  
    IEnumerator Spawn ()
    {
        yield return new WaitForSeconds (2.0f);
      
        while (!gameOver) {
          
            Vector3 spawnPosition = new Vector3 (
                Random.Range (-maxWidth, maxWidth),
                transform.position.y,
                0.0f
                );
            Quaternion spawnRotation = Quaternion.identity;
            Instantiate (ball, spawnPosition, spawnRotation);
            yield return new WaitForSeconds (Random.Range (1.0f, 2.0f));
        }
        yield return new WaitForSeconds (2.0f);
        gameOverText.SetActive (true);
        yield return new WaitForSeconds (2.0f);
        restartButton.SetActive (true);
    }
}

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.

2 Likes