I have a problem with the light

Hi. I have a problem. I have made a light in Unity and made it follow the character on screen, but when the character takes damage and dies, an error pops up that says like this:

“MissingReferenceException: The object of type ‘GameObject’ 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.”

I know what the error is, and how I could fix it, but since I’m so dumb, I don’t know how to code what I want to do? Can you help me?:(:frowning: this is the script for the light:

   public GameObject NinjaFrog;
    void Update()
    {
        Vector3 position = transform.position;
        position.x = NinjaFrog.transform.position.x;
        position.y = NinjaFrog.transform.position.y;
        transform.position = position;
    }

(NinjaFrog is the object for the follow)

   public GameObject NinjaFrog;
    void Update()
    {
    if(ninjaFrog == null)return;
        Vector3 position = transform.position;
        position.x = NinjaFrog.transform.position.x;
        position.y = NinjaFrog.transform.position.y;
        transform.position = position;
    }
1 Like

Thanks so much for your help!

1 Like