I don't understand the mistake that comes out

I get these 3 errors but I don’t understand why, please help
Error 1: NullReferenceException: Object reference not set to an instance of an object
Recordatorio.Start () (at Assets/ScriptGuardarCargar/Recordatorio.cs:20)

Error 2: NullReferenceException: Object reference not set to an instance of an object
Recordatorio.OnTriggerEnter (UnityEngine.Collider other) (at Assets/ScriptGuardarCargar/Recordatorio.cs:33)

Error 3: NullReferenceException: Object reference not set to an instance of an object
Recordatorio.OnTriggerExit (UnityEngine.Collider o) (at Assets/ScriptGuardarCargar/Recordatorio.cs:42)

[FONT=Helvetica]using System.Collections;[/FONT]
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class Recordatorio : MonoBehaviour
{

  //  bool active;
 //   Canvas canvas;
    public Image Imagen;

    void Start()
    {

   //     canvas = GetComponent<Canvas>();
     //   canvas.enabled = false;

        Imagen = GetComponent<Image>();
        Imagen.enabled = false;
        
    }

    void Update()
    {

    }

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
         //   Imagen = GetComponent<Image>();
            Imagen.enabled = true;
            Debug.Log("Entraste!");
    }

    void OnTriggerExit(Collider o)
    {
        if (o.CompareTag("Player"))
        {
        //    Imagen = GetComponent<Image>();
            Imagen.enabled = false;
            Debug.Log("saliste");

        }
    }
}

Did you drag an Image instance into the field on line 11?

If so, then REMOVE line 19 because that would replace it with whatever Image is found on the current GameObject, which might be none.

Thanks bro, i’m noob in this theme

1 Like

You’re welcome! Keep at it and one day you’ll look up and smile and say “I’m not a noob anymore!”

1 Like