Trying to show ads at a certain score.

Hello there I wrote this to show ads when the player gets to score 3000 however it is not working can you give me a hint on what im doing wrong?

    public void AddScore(int n)
    {
        currentScore += n;
        adScore += n;
        text_score.text = currentScore.ToString();
        if (adScore >= 3000)
        {
            GetComponent<AdsMan>();
            adScore = 0;
        }
    }

And here is AdsMan:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdsMan : MonoBehaviour
{
    IEnumerator Start()
    {
        Advertisement.Initialize("-------", true); //dont mind the -'s its correct in the code
        while (!Advertisement.IsReady())
        {
            yield return null;
        }
            Advertisement.Show();
    }
}

With your code you’re only getting the AdsMan script, not showing the ad with it.
Try this:

GetComponenet<AdsMan>().Start();

This will run the Start() function when it’s called.

Oh yeah right! it seems its not only that but i also forgot to add public to IEnumerator. Although its still not working.

U need this to start thr Coroutine

StartCoroutine(Start);

1 Like

Start is a coroutine on a Monobehaviour, which Unity will automatically run when the Monobehaviour is created.

I would suggest renaming the Start function to avoid this (probably) unwanted behavior (e.g. rename it to ShowAdd) and starting the coroutine manually

StartCoroutine(GetComponent<AdsMan>().ShowAdd());