Search Unity

Help with implementing Banner ADS?

Discussion in 'Unity Ads & User Acquisition' started by BL4CK0UT19, Aug 29, 2019.

  1. BL4CK0UT19

    BL4CK0UT19

    Joined:
    Aug 21, 2019
    Posts:
    75
    Hi!
    So,this is the first time i'm using ADS (also the first time im making a game,but the game mechanics are working fine :p) and i have no clue on how to display a banner ADS.
    I can display Video ADS with no problems (i watched a guide on how to do it),but im not finding any good guide on how to easily implement banners. Can someone show me how do i put a simple banner AD on my game?
    Im gonna let the code im using for the ADS here,but you can just show me your own code if you want :)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.UI;
    6. using UnityEngine.Advertisements;
    7.  
    8. public class BotãoStart : MonoBehaviour
    9. {
    10.     string gameId = "MYGAMEID";
    11.     public AudioSource ButtonClick;
    12.  
    13.  
    14.     private Button quitbutton;
    15.  
    16.  
    17.  
    18.     void Awake()
    19.     {
    20.         Advertisement.Initialize(gameId);
    21.     }
    22.  
    23.     public void startthegame()
    24.     {
    25.         ButtonClick = GetComponent<AudioSource>();
    26.         SceneManager.LoadScene(1);
    27.         ButtonClick.Play();
    28.     }
    29.  
    30.     public void startthegame2()
    31.     {
    32.         if (Advertisement.IsReady("video"))
    33.  
    34.         {
    35.             Advertisement.Show("video");
    36.         }
    37.         ButtonClick = GetComponent<AudioSource>();
    38.         SceneManager.LoadScene(0);
    39.         ButtonClick.Play();
    40.     }
    41.  
    42.     public void startthegame3()
    43.     {
    44.      
    45.         ButtonClick = GetComponent<AudioSource>();
    46.         SceneManager.LoadScene(2);
    47.         ButtonClick.Play();
    48.     }
    49.  
    50.     public void closethegame()
    51.     {
    52.         ButtonClick = GetComponent<AudioSource>();
    53.         ButtonClick.Play();
    54.         Application.Quit();
    55.     }

    Also,one last question: My video ADS are working 100% fine on editor and on mobile (test mode only),but i don't seem to be able to skip my video AD...Is that because is it test mode or anything like that? Because i have already marked to allow video skipping on the dashboard...
    Thanks!
     
  2. BL4CK0UT19

    BL4CK0UT19

    Joined:
    Aug 21, 2019
    Posts:
    75
  3. BL4CK0UT19

    BL4CK0UT19

    Joined:
    Aug 21, 2019
    Posts:
    75
    bumping again
     
  4. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @BL4CK0UT19

    This is what I would recommend for banners. This will Load a banner and show it once it's ready. (You can also make them separate calls if you prefer; load at init, then show the banner only on specific screens.)

    This will also make it a bit easier to debug why a banner might not be showing. (We are working to improve banner availability, but it's possible you will get No Fill when requesting a banner.)

    Code (CSharp):
    1. string placement = "banner";
    2. public void LoadBanner()
    3. {
    4.     if(!Advertisement.Banner.isLoaded)
    5.     {
    6.         BannerLoadOptions loadOptions = new BannerLoadOptions
    7.         {
    8.             loadCallback = OnBannerLoaded,
    9.             errorCallback = OnBannerError
    10.         };
    11.         Advertisement.Banner.Load(placement, loadOptions);
    12.     }
    13. }
    14. void OnBannerLoaded()
    15. {
    16.     Debug.Log("Banner Loaded");
    17.     Advertisement.Banner.Show(placement);
    18. }
    19. void OnBannerError(string error)
    20. {
    21.     Debug.Log("Banner Error: " + error);
    22. }
    23.  
    They should still be skippable in test mode, but by default it won't happen until after 5 seconds. The skip button will be on the top, left side corner of the screen.