0
\$\begingroup\$

How Can I Apply Ads Different Level?? I Create A 40 Level,

Ex:

  • Level1 complete then load ads Interstitial
  • Level2 complete then load ads Interstitial
  • Level3 complete then load ads Rewarded
  • Level4 complete then load ads Rewarded
  • Level5 complete then load ads Interstitial
  • Level6 complete then load ads Interstital

follow this same pattern in further levels(40)

Code:

 public string currentscenename;

 public string nextscenename;

 public void Next()        //code for next level                                
  {
        int num = PlayerPrefs.GetInt("Level", 0);            
        Debug.Log("Num1:" + num);            
        num++;                                                                                                             

        PlayerPrefs.SetInt("Level", num);   

        if (currentscenename == nextscenename)                                  
        {
            Next();
            Debug.Log("loadlevel");
        }
        else
        { 
             if (num % 4 == 3 || num % 4 == 0)         // it is working absolutely fine                                                                                           
            {
                //DebugPanel.Log("num1", "num2" + num % 4);

                if (rewardBasedVideo.IsLoaded())                                                                                
                {
                     rewardBasedVideo.Show();   //this line generate reward ads
                    //DebugPanel.Log("rewarded", "rewardedads");
                    //DebugPanel.Log("inside ads" , "inside ads function");
                    Debug.Log("rewarded 1");
                }
            }
            if(num % 4 == 2 || num % 4 == 1)                                                                                               //1 and 2 
            {
                myclass.CallAds.Instance.AdsRequest();    //this line generate interstitial ads
                DebugPanel.Log("num" , "num" + num % 4);
                Debug.Log("interstitial 2");
            }
            SceneManager.LoadScene(nextscenename);
        }
  }





**Maths:**     problem is here my condition will not be run when coming Level5 and Level10,Level15,Level20,Level25,Level30,Level35,Level40
5 mod 4 =  1
10 mod 4 = 2     


Problem is when coming Level5 and Level10 then not showning ads????plz help


I m Using Google AdmobAds: https://developers.google.com/admob/unity/start

Referance:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Other users might be able to help you better if you mention which Ad network you are using \$\endgroup\$ – Shraa1 Jul 15 at 11:40
  • \$\begingroup\$ @Shraa1 i m using google admob ads \$\endgroup\$ – jishan nuran Jul 15 at 11:43
0
\$\begingroup\$

You can use OnLevelWasLoaded(int level) but will be depreciated sometime so the docs say to subscribe to the SceneManagers sceneLoaded

using UnityEngine.SceneManagement;

public class YourAdScript: MonoBehaviour
{
   void Start
   {
     SceneManager.sceneLoaded+= this.OnLevelLoaded;   
   }

   void OnLevelLoaded(Scene scene,LoadSceneMode mode)
   {
     //play ad
     if(rewardBasedVideo.IsLoaded())                                                                                
       {
          rewardBasedVideo.Show();//this line generate rewarded ads
       }
   }
   void OnDisable
   {
      SceneManager.sceneLoaded-= this.OnLevelLoaded;   
   }
}

note : be sure to unsubscribe in OnDisable().

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.