D
D
dkcu2021-03-27 16:32:35
Unity
dkcu, 2021-03-27 16:32:35

Why does it throw this error MissingReferenceException: The object of type 'Text' has been destroyed?

Throws this error
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.

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("315925", 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!
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-03-27
@freeExec

Translate the error at least in Google. She reveals her essence completely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question