How to open the door after picking up the keyObject?

I am trying to open the door when the player pick-up the key and becomes next to the door, depending on OnTriggerEnter function. I called OnTriggerEnter function in the script of PicUpKey.cs but the door opens once the player picks up the key. I want the door open when the player carries the key and goes to the door. PLEASE HELP.

PicUpKey.cs is below:

public class PicUpKey : MonoBehaviour
{
    public GameObject keyObject, PicUpTextKey ;
    
    public RawImage objectRawImageKey;

    public Door door;

    void Start()
    {
        keyObject.SetActive(false);
        objectRawImageKey.enabled = false;
        PicUpTextKey.SetActive(false);
    }

    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            PicUpTextKey.SetActive(true);
            if (Input.GetKey(KeyCode.K))
            {
                gameObject.SetActive(false);
                keyObject.SetActive(true);
                objectRawImageKey.enabled = true;
                PicUpTextKey.SetActive(false);

               //calling OnTriggerEnter when the player pics up the key
                if(objectRawImageKey.enabled == true)
                {
                    door.OnTriggerEnter(other);
                }
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        PicUpTextKey.SetActive(false);
    }

}

Door.cs is below:

public class Door : MonoBehaviour
    {
        public GameObject AnimeObject;
        public GameObject ThisTrigger;
    
        private void Start()
        {
            ThisTrigger.SetActive(false);
        }
        
    
        public void OnTriggerEnter(Collider collision)
        {
            if (collision.transform.tag == "Player")
            {
                AnimeObject.GetComponent<Animator>().Play("Door");
                ThisTrigger.SetActive(true);
            }
        }
    }

Please help.

Hi,
First things first, you shouldn’t really call door.OnTriggerEnter(other); directly OnTrigger… functions call themselves as you enter into the trigger. Saying that PicUpKey doesn’t have to have reference to door but rather a public boolean called keyCollected or smth and door class will have a reference to that key class. Now you can check if key was collected by checking aforementioned bool.

 public class Door : MonoBehaviour
     {
         public GameObject AnimeObject;
         public GameObject ThisTrigger;
         public PicUpKey key;
     
         private void Start()
         {
             ThisTrigger.SetActive(false);
         }
         
     
         public void OnTriggerEnter(Collider collision)
         {
             if (collision.transform.tag == "Player" && key.keyCollected == true)
             {
                 AnimeObject.GetComponent<Animator>().Play("Door");
                 ThisTrigger.SetActive(true);
             }
         }
     }