public void ShowReward2Ad()

    {

        if (gameDirector.adDiceCooltime <= 0) <---------------------------- 여기서 에러남

        {

            if (gameDirector.isNoAdAndAutoPurchased)

            {

                gameDirector.dice += 5;

                gameDirector.adDiceCooltime = 300;

            }

            else

            {

                rewardAd2.Show();

                LoadReward2Ad();

            }

        }

        

    }


광고 보기 버튼을 누르면 해당 함수가 작동되게 되어있음

그런데 위에 표시한 곳에 널레퍼런스익셉션 에러가 뜸

느낌상 광고 보여줄 때 if문 같은 거 넣으면 안 되는 것 같은데 이유 알려줄 수 있음?


아래는 전체 코드임 (고라니TV꺼 보고 따라한 것에 if문 추가함)


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using GoogleMobileAds.Api;


public class PurchaseDirector : MonoBehaviour

{

    GameDirector gameDirector;

    public Button AdAutoAttack;

    public Button AdDice;


    public bool isTestMode = true;

    void Start()

    {

        gameDirector = GetComponent<GameDirector>();

        LoadReward1Ad();

        LoadReward2Ad();

    }


    void Update()

    {

        AdAutoAttack.interactable = rewardAd1.IsLoaded();

        AdDice.interactable = rewardAd2.IsLoaded();

    }


    AdRequest GetAdRequest()

    {

        return new AdRequest.Builder().AddTestDevice(내 디바이스 아이디).Build();

    }


    string rewardTestID = "ca-app-pub-3940256099942544/5224354917"; // 테스트 광고 아이디

    string reward1ID = (내 리워드 광고 1 아이디);

    string reward2ID = (내 리워드 광고 2 아이디);

    RewardedAd rewardAd1;

    RewardedAd rewardAd2;


    void LoadReward1Ad()

    {

        rewardAd1 = new RewardedAd(isTestMode ? rewardTestID : reward1ID);

        rewardAd1.LoadAd(GetAdRequest());

        rewardAd1.OnUserEarnedReward += (sender, e) =>

        {

            gameDirector.adAutoAttackTime += 300 * gameDirector.optionAdAutoAttackTimeMultiple;

            gameDirector.StatSync();

        };

    }


    public void ShowReward1Ad()

    {

        if (gameDirector.adAutoAttackTime <= 0) <---------------------------- 여기서 에러남

        {

            if (gameDirector.isNoAdAndAutoPurchased)

            {

                gameDirector.adAutoAttackTime += 300 * gameDirector.optionAdAutoAttackTimeMultiple;

                gameDirector.StatSync();

            }

            else

            {

                rewardAd1.Show();

                LoadReward1Ad();

            }

        }

        

    }


    void LoadReward2Ad()

    {

        rewardAd2 = new RewardedAd(isTestMode ? rewardTestID : reward2ID);

        rewardAd2.LoadAd(GetAdRequest());

        rewardAd2.OnUserEarnedReward += (sender, e) =>

        {

            gameDirector.dice += 5;

            gameDirector.adDiceCooltime = 300;

        };

    }


    public void ShowReward2Ad()

    {

        if (gameDirector.adDiceCooltime <= 0) <---------------------------- 여기서 에러남

        {

            if (gameDirector.isNoAdAndAutoPurchased)

            {

                gameDirector.dice += 5;

                gameDirector.adDiceCooltime = 300;

            }

            else

            {

                rewardAd2.Show();

                LoadReward2Ad();

            }

        }

        

    }



}