Share via

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

Elizabeth de Santiago 1 Reputation point
2021-05-13T04:15:22.95+00:00

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!

Community Center | Not monitored

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.