question

ElizabethdeSantiago-3269 avatar image
0 Votes"
ElizabethdeSantiago-3269 asked Viorel-1 commented

Error on script Null Reference Unable to find instance of an object

Hi all!

My class group is struggling with finding our current error. We are trying to have our player collide into a game object which triggers an entry into a journal. We are getting the error NullReferenceException: Object reference not set to an instance of an object.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FirstPersonController : MonoBehaviour
{
public GameObject dialoguePanel;
public GameObject infoText;
public GameObject journalPanel;

 public GameObject Pots;





void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "InfoGiver")
{
ShowDialoguePanel();
//print(other.gameObject.name);
//dialoguePanel.SetActive(true);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;

         if (other.gameObject.name == "Pots")
         {
             infoText.GetComponent<UnityEngine.UI.Text>().text = "Bob: \"I work at the farm here in town as a horsehand. I'm sad to see our dear llama missing.\"";
         }


Are there any evident errors in this text that we are not noticing?

Thank you in advance for any suggestions you may have!

not-supported
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you determine the problematic line (using Debugger or examining exception details)? Maybe the unassigned infoText is null or GetComponent<UnityEngine.UI.Text>() cannot find the component.


0 Votes 0 ·

0 Answers