When ball hits wall bottom for 15th time , intstead of ad i get error : NullReferenceException: Object reference not set to an instance of an object BallScript.Start () (at Assets/BallScript.cs:44)

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Advertisements;

public class BallScript : MonoBehaviour

private ManagerAds ads;

public Vector2 startForce;

static int times = 0;

public Text goverText;

public Vector3[] positions;

public Rigidbody2D rb;

void Start()
    int randomNumber = Random.Range(0, positions.Length);
    transform.position = positions[randomNumber];
    times = PlayerPrefs.GetInt("Played:", times);
    rb.AddForce(startForce, ForceMode2D.Impulse);
    ads = GameObject.FindObjectOfType<ManagerAds>();


void Update()

    PlayerPrefs.SetInt("Played:", times);
    goverText.text = "Played:" + times.ToString();


void OnCollisionEnter2D(Collision2D other)
    if (other.gameObject.name == "wall_bottom")


        if (times == 15 )






It seems it can’t find the object to work with.
ads.PlayRewardedAd() at line 44 can’t be executed because ads is probably not set. Make ads (first line) public instead of private and then try to see during execution if it is void or not. Probably the problem is at line 21:
ads = GameObject.FindObjectOfType();

It’s telling you your ‘ads’ variable is null, which suggests that


is returning null, which suggests that at the point in time when the Start() function is called, either you have no gameobject in your scene with a ManagerAds component attached, or that object is disabled.