@dkcu

Возникает ошибка MissingReferenceException: The object of type 'Text' has been destroyed. как решить?

Иногда возникает эта ошибка
MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
Вот код
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.UI;

public class UnityAds : MonoBehaviour, IUnityAdsListener
{
    
    string placement = "rewardedVideo";
    public float money;
    public Text moneyTxt;

    void Start()
    {
        money = PlayerPrefs.GetFloat("money");
        Advertisement.AddListener(this);
        Advertisement.Initialize("4037117", true);
    }

    public void ShowUnityAD(string p)
    {
        Advertisement.Show(p);
    }

    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        if (showResult == ShowResult.Finished)
        {
            moneyTxt.text = "Money:" + money++; 
        }
        else if (showResult == ShowResult.Failed)
        {
            //On no!
        }
    }

    public void OnUnityAdsDidStart(string placementId)
    {
    }

    public void OnUnityAdsReady(string placementId)
    {
    }

    public void OnUnityAdsDidError(string message)
    {
    }
}

Прошу ответить подробно
Зарание спасибо.
  • Вопрос задан
  • 80 просмотров
Решения вопроса 1
freeExec
@freeExec
Участник OpenStreetMap
moneyTxt на момент использования не существует.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы