Why wont my triggers work?

this is my trigger

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

public class OpenDoor : MonoBehaviour
{
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        void OnTriggerEnter2D(Collision2D collision){
            gameObject.BroadcastMessage("OpenDoor", 5.0);
        }
    }
    
}

this is the thing that is suposed to do something

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

public class DoorOpened : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        void OpenDoor(float door){
            Debug.Log("door");
        }
    }
}

when i run into my trigger the word Door doesnt pop up in my console. whats happening and how do i fix it? P.S. this one of my first games, so sorry if its simple

Why is your OnTriggerEnter2D function declared as a local function inside of Update? It should be a method added the to the MonoBehaviour class itself, otherwise the event will never be invoked. Here’s the correct code:

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

public class OpenDoor : MonoBehaviour
{
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    void OnTriggerEnter2D(Collision2D collision){
        gameObject.BroadcastMessage("OpenDoor", 5.0);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    
}