if (loadCount % 3 == 0) // only show ad every third time { not working

you mead csripts

void OnTriggerEnter2D(Collider2D col)
{
    if (LayerMask.LayerToName (col.gameObject.layer).Equals (NinjaRopeConst.PLAYER_CHILD))
    {
        if (GameOverDialog != null) {
            GameOverDialog.SetActive (true);
        }

        gameOver = true;
        //loadCount ++;
        Destroy (col.gameObject.transform.parent.gameObject);

        if (loadCount % 3 == 0) // only show ad every third time
        {
            ///ShowAd();
            LoadTheLevel();
        }
    }
}

public void LoadTheLevel()
{
    LevelGenerate = Random.Range(1, 5);
    SceneManager.LoadScene(LevelGenerate);
}

this is a death by player count every 3rd time player dies public void LoadTheLevel() loads random scene.
but the if (loadCount % 3 == 0) doesn’t work every 3rd death,1st,7th death yes

entire code-------

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

namespace NinjaRope
{
    public class GameOverController : MonoBehaviour
    {
        public GameObject GameOverDialog;
        private bool gameOver = false;
        static int loadCount = 0;
        public int LevelGenerate;

        void Awake()
        {
            if (GameOverDialog != null)
            {
                GameOverDialog.SetActive (false);
            }
            else
            {
                Debug.Log ("*** Add a GameOver-Dialog to the uGUI ***");
            }
        }

        //void Start()
        //{
        //loadCount = 0;
        //}

        void OnTriggerEnter2D(Collider2D col)
        {
            if (LayerMask.LayerToName (col.gameObject.layer).Equals (NinjaRopeConst.PLAYER_CHILD))
            {
                if (GameOverDialog != null)
                {
                    GameOverDialog.SetActive (true);
                }

                gameOver = true;
                //loadCount ++;
                Destroy (col.gameObject.transform.parent.gameObject);

                if (loadCount % 3 == 0) // only show ad every third time
                {
                    ///ShowAd();
                    LoadTheLevel();
                }
            }
        }

        public void LoadTheLevel()
        {
            LevelGenerate = Random.Range(1, 5);
            SceneManager.LoadScene(LevelGenerate);
        }

        void Update()
        {
            if (gameOver)
            {
#if UNITY_EDITOR
                if (Input.GetMouseButtonDown (0))
                {
                    SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
                }
#endif

                if (Input.touchCount > 0)
                {
                    foreach (Touch t in Input.touches)
                    {
                        if (t.phase == TouchPhase.Began)
                        {
                            SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
                        }
                    }
                }
            }
        }
    }
}

Hi, you seem to have commented out the lines which increments loadCount variable in your code above? Can you edit the post, so it’s showing when you are incrementing/showing ad?

Thanks,
Rasmus

i put loadCount ++; back in not working every 3rd time suppose to change level and it does but not every 3rd time

My best suggestion for now is to add Debug.Log() statements in your code, when you are incrementing loadCount, to see if that actually happens when you expect it to happen? Could be that the OnTriggerEnter2D() method gets called multiple times because of multiple gameobjects or something?

Just a guess…

/Rasmus

I have a same issue. My script has clickCount %2 == 0{ Show.Ads } However, after 5 advertisements it stops. Nothing show up at 12 14 16 … etc. Still dunno why :S