Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Show Admob interstitial in Game Over and Level Win

Discussion in 'Scripting' started by jorgegb1997, Jun 14, 2015.

  1. jorgegb1997

    jorgegb1997

    Joined:
    Apr 15, 2014
    Posts:
    56
    Hello!

    I already have all the packages in my project of admob (with normal banner and interstitial), but i can´t put the interstitial showing after game over menu and level win menu..

    I have the google mobile ads demo script, but i can´t make the ads appears in the end of the game...

    Heres my gamemanager code:
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine.UI;
    3.  
    4.  
    5. public class GameManager : MonoBehaviour {
    6.     public int LevelNumber;
    7.     public GameObject imgStar1;
    8.     public GameObject imgStar2;
    9.     public GameObject imgStar3;
    10.     public AudioClip audPickup;
    11.     public AudioClip audWin;
    12.     public AudioClip audCrash;
    13.     //Panels
    14.     public GameObject PausePanel;
    15.     public GameObject PlayingPanel;
    16.     public GameObject WinPanel;
    17.     public GameObject LosePanel;
    18.     public GameObject SettingsPanel;
    19.     public Text txtGraphics;
    20.     public Text MuteText;
    21.  
    22.     GameObject player;
    23.  
    24.     int StarsCollected;
    25.     // Use this for initialization
    26.     void Start () {
    27.         player = GameObject.FindGameObjectWithTag("Player");
    28.         Time.timeScale = 1;
    29.         StarsCollected = 0;
    30.  
    31.  
    32.         //Gets whether the sound is set to muted, and changes audio settings accordingly.
    33.         if (PlayerPrefs.GetInt("SoundSettings") == 1)
    34.         {
    35.             AudioListener.pause = false;
    36.             MuteText.text = "";
    37.         } else if (PlayerPrefs.GetInt ("SoundSettings") == 0)
    38.         {
    39.             AudioListener.pause = true;
    40.             MuteText.text = "/";
    41.         }
    42.  
    43.         txtGraphics.text = GetQualityName (QualitySettings.GetQualityLevel());
    44.     }
    45.  
    46.  
    47.  
    48. public    void CollectStar ()
    49.     {
    50.         audio.PlayOneShot (audPickup);
    51.         StarsCollected += 1;
    52.  
    53.         if (StarsCollected == 1)
    54.             imgStar1.SetActive (true);
    55.         if (StarsCollected == 2)
    56.             imgStar2.SetActive (true);
    57.         if (StarsCollected == 3)
    58.             imgStar3.SetActive (true);
    59.  
    60.     }
    61.  
    62.     public void CollectTime()
    63.     {
    64.         audio.PlayOneShot (audPickup);
    65.     }
    66.  
    67.  
    68. public void LevelWin ()
    69.     {
    70.         int lvlULTemp = PlayerPrefs.GetInt("LevelsUnlocked");
    71.         if (lvlULTemp == LevelNumber)
    72.             PlayerPrefs.SetInt("LevelsUnlocked",lvlULTemp+1);
    73.  
    74.         Time.timeScale = 0;
    75.         int tempStars = PlayerPrefs.GetInt ("Level" + LevelNumber.ToString () + "Stars");
    76.         audio.PlayOneShot (audWin);
    77.         if (tempStars < StarsCollected)
    78.         {
    79.             PlayerPrefs.SetInt ("Level" + LevelNumber.ToString () + "Stars", StarsCollected);
    80.         }
    81.  
    82.         PausePanel.SetActive (false);
    83.         PlayingPanel.SetActive (false);
    84.         WinPanel.SetActive (true);
    85.         LosePanel.SetActive (false);
    86.         SettingsPanel.SetActive (false);
    87.  
    88.         }
    89.  
    90.  
    91. public    void LevelLose()
    92.     {
    93.         player.audio.Stop();
    94.         audio.PlayOneShot (audCrash);
    95.         PausePanel.SetActive (false);
    96.         PlayingPanel.SetActive (false);
    97.         WinPanel.SetActive (false);
    98.         LosePanel.SetActive (true);
    99.         SettingsPanel.SetActive (false);
    100.         Time.timeScale = 0;
    101.         Debug.Log ("Level Lose");
    102.     }
    103.  
    104.     /////////////////////////////
    105.     ////////////////////////////
    106.     ///////UI FUNCTIONS////////
    107.     //////////////////////////
    108.  
    109.  
    110.     public void PreviousLevel()
    111.     {
    112.  
    113.         Application.LoadLevel (Application.loadedLevel - 1);
    114.     }
    115.  
    116.     public void NextLevel()
    117.     {
    118.  
    119.         if(Application.loadedLevel <22)
    120.         {
    121.         Application.LoadLevel (Application.loadedLevel + 1);
    122.         } else {
    123.             Application.LoadLevel (0);
    124.         }
    125.     }
    126.  
    127.     public void Restart()
    128.     {
    129.  
    130.         Application.LoadLevel (Application.loadedLevel);
    131.     }
    132.  
    133.     public void SwitchToMenu()
    134.     {
    135.         Time.timeScale = 1;
    136.         Application.LoadLevel (0);
    137.     }
    138.  
    139.      public void Pause()
    140.     {
    141.     PausePanel.SetActive (true);
    142.     PlayingPanel.SetActive (false);
    143.     WinPanel.SetActive (false);
    144.     LosePanel.SetActive (false);
    145.     SettingsPanel.SetActive (false);
    146.     Time.timeScale = 0;
    147.  
    148.     }
    149.  
    150.     public void Unpause()
    151.     {
    152.         Time.timeScale = 1;
    153.         PausePanel.SetActive (false);
    154.         PlayingPanel.SetActive (true);
    155.         WinPanel.SetActive (false);
    156.         LosePanel.SetActive (false);
    157.         SettingsPanel.SetActive (false);
    158.     }
    159.  
    160.     public void Settings()
    161.     {
    162.         PausePanel.SetActive (false);
    163.         PlayingPanel.SetActive (false);
    164.         WinPanel.SetActive (false);
    165.         LosePanel.SetActive (false);
    166.         SettingsPanel.SetActive (true);
    167.     }
    168.  
    169.     public void ChangeGraphics(string GraphicsSet)
    170.     {
    171.         if(GraphicsSet == "up")
    172.         {
    173.             QualitySettings.IncreaseLevel();
    174.         }else if(GraphicsSet == "down")
    175.         {
    176.             QualitySettings.DecreaseLevel();
    177.         }
    178.         txtGraphics.text = GetQualityName (QualitySettings.GetQualityLevel());
    179.     }
    180.  
    181.  
    182.     public void ToggleSound()
    183.     {
    184.         int tempSound = PlayerPrefs.GetInt ("SoundSettings");
    185.        
    186.         if (tempSound == 1) {
    187.             PlayerPrefs.SetInt("SoundSettings",0);
    188.             //audio.mute = true;
    189.             AudioListener.pause = true;
    190.             MuteText.text = "/";
    191.         } else if (tempSound == 0) {
    192.             PlayerPrefs.SetInt("SoundSettings",1);
    193.             //audio.mute = false;
    194.             MuteText.text = "";
    195.             AudioListener.pause = false;
    196.         }
    197.     }
    198.  
    199.    
    200.     public string GetQualityName(int qualityNo)
    201.     {
    202.         string[] names;
    203.         names = QualitySettings.names;
    204.        
    205.         return names[qualityNo];
    206.     }
    207. }
    208.  

    Anyone can help me?

    PS: I already have all the pachages in my projects and i already install the sdk.. I just need to put in game over and level win..
     
  2. jorgegb1997

    jorgegb1997

    Joined:
    Apr 15, 2014
    Posts:
    56
    some help? Some video tutorial?