Search Unity

Placing admob banners ads in singleton

Discussion in 'Unity Ads & User Acquisition' started by mitsuko-ono, May 12, 2021.

  1. mitsuko-ono

    mitsuko-ono

    Joined:
    Mar 9, 2021
    Posts:
    5
    I have a game with several scenes. I want to put a banner on every scene and play an interstitial ad after pressing the "play again" button on a game over scene.

    If i put a banner gameobject with a banner script on every scene, it will initialize the script every scene right? so I tried to make a gameobject with a banner script + singleton so it doesn't need to initialize on every scene but will only load on the splash screen. Though every time I play, i only see the banner on the splash screen and it disappears on the next screen but the gameobject with the script is still there. How can I make the banner ad appear on every scene without having to load it every time there's a new scene? Or maybe i'm doing it wrong but can somebody help me?

    the singleton code i used on Ads Controller gameobject.
    (banner ad and interstitial is a child of Ads Controller gameobject)
    (i placed Ads controller game object only in my splash screen but i want it to persist on all the scenes)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AdsController : MonoBehaviour
    6. {
    7.     private void Awake()
    8.     {
    9.         SetUpSingleton();
    10.     }
    11.  
    12.     private void SetUpSingleton()
    13.     {
    14.         int numberOfAdCOntroller = FindObjectsOfType<AdsController>().Length;
    15.         if (numberOfAdCOntroller > 1)
    16.         {
    17.             Destroy(gameObject);
    18.         }
    19.         else
    20.         {
    21.             DontDestroyOnLoad(gameObject);
    22.         }
    23.  
    24.  
    25.     }
    26. }
     
  2. Chapsiz

    Chapsiz

    Joined:
    Feb 11, 2020
    Posts:
    2
    Hello, I am trying to solve the same problem. Did you find any fix ?
     
  3. Chapsiz

    Chapsiz

    Joined:
    Feb 11, 2020
    Posts:
    2
    Anyone ?
     
  4. Indrit_Vaka

    Indrit_Vaka

    Joined:
    Jun 6, 2020
    Posts:
    4
    Hello!
    I suggest you have a scene (Like Boot), one which will start up and all the other scenes will be rendered there, so you just add the scene you want to load there, in the existing loaded scene.
    In that Scene add all the scripts... you don't what to initialize for each scene
    upload_2022-3-29_7-58-42.png