I am getting this error
NullReferenceException: Object reference not set to an instance of an object
chucknorris1+d__4.MoveNext () (at Assets/chucknorris1.cs:41)
when running my script. The debug log returns the desired text, but the text is not shown in the textmeshrpo field (it is not assigned to _chuckjoke)
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using SimpleJSON;
using TMPro;
public class chucknorris1 : MonoBehaviour
{
private TextMeshPro _chuckJoke;
private const string URL = "https://api.chucknorris.io/jokes/random";
private void start()
{
_chuckJoke = FindObjectOfType();// GameObject.Find("OutputArea").GetComponent();
}
public void GenerateRequest()
{
StartCoroutine(ProcessRequest(URL));
}
private IEnumerator ProcessRequest(string uri)
{
using (UnityWebRequest request = UnityWebRequest.Get(uri))
{
yield return request.SendWebRequest();
if (request.isNetworkError)
{
Debug.Log(request.error);
}
else
{
Debug.Log(request.downloadHandler.text);
JSONNode itemsData = JSON.Parse(request.downloadHandler.text);
Debug.Log("The generated item is: \nName: " + itemsData["value"]);
_chuckJoke.SetText($"Jkoe is :{itemsData["value"]}");
}
}
}
}
↧