Start unity ads when you die.

Hello ! I want start ads when you die after 3 times but no working.
here is my code :

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

public class dead : MonoBehaviour {

// Use this for initialization
public int deadcount;
void Start () {
deadcount = 0;
}

// Update is called once per frame
void Update () {

}

void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == “Player”) {
deadcount++;
SceneManager.LoadScene (“restart”);
}
}
void deadads()
{
if (deadcount == 3) {
Advertisement.Show ();
}
}

}

Maybe because every time you increment deadcount, you then reload the scene, which resets deadcount back to zero.

I do this but still not working. Thank you !

Also see How to make unity ads show every 3 death? Please be specific, thank you. - Unity Services - Unity Discussions

I try this but no working, showing ad imedietly after enter in scene…Can you edit my code?

Not sure which code you are referring to, but as SteveJ suggested, seems you are resetting your scene everytime you die, by setting deadCount = 0 in Start() method.

I think following could help:

  1. Change “public int deadcount;” to “public static int deadcount = 0;”
  2. Remove “deadcount = 0;” from your Start() method

Where do you actually call the deadads() method from?

/Rasmus

Thank you ! Wooork !

1 Like