I am trying to show interstitial ads when the player clicks on specific button (hint button), but Unity is giving me this error:
> NullReferenceException: Object reference not set to an instance of an
> object ButtonManager.Hint()...
This is the code for showing the ad:
public class ButtonManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Reload()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void Home()
{
SceneManager.LoadScene("MainMenu");
}
int contc;
public void Play()
{
SceneManager.LoadScene("LevelMenu");
}
public void Hint()
{
FindObjectOfType<AdMobManager>().Hint = true;
FindObjectOfType<AdMobManager>().showInterstitial();
}
Any idea how can I get around this problem?
That is a C# error, you are trying to use a null Object. I think the problem is: FindObjectOfType()
Check if you really get any object with that Find.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.