Solving interaction and collision problem

I have created a key door system using Raycast from sppedtutors tutorial.

But there is a problem. I have placed the key inside the drawer but and wanted the player to first open the door of drawer and take the key from it but it is not working as i expected as i can get the key without opening the drawer pls help me to fix it.

You can get the information of it from his video:

Maybe you can activate the key script when the drawer is opened like keyScript.enabled=true; and make public KeyScript keyScript;

Or just send the script i will try.

the following is the drawer controller sript

using System.Collections;

using System.Collections.Generic;
using UnityEngine;

public class Doors : MonoBehaviour
{
    public Animator door;
    public GameObject openText;

    public AudioSource doorSound;


    public bool inReach;




    void Start()
    {
        inReach = false;
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Reach")
        {
            inReach = true;
            openText.SetActive(true);
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Reach")
        {
            inReach = false;
            openText.SetActive(false);
        }
    }





    void Update()
    {

        if (inReach && Input.GetButtonDown("Interact"))
        {
            DoorOpens();
        }

        else
        {
            DoorCloses();
        }




    }
    void DoorOpens ()
    {
        //Debug.Log("It Opens");
        door.SetBool("Open", true);
        door.SetBool("Closed", false);
        doorSound.Play();

    }

    void DoorCloses()
    {
        Debug.Log("It Closes");
        door.SetBool("Open", false);
        door.SetBool("Closed", true);
    }


}

the following is interactive item controler key

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

namespace KeySystem
{
    public class KeyItemController : MonoBehaviour
    {
        [SerializeField] private bool maindoor = false;
        [SerializeField] private bool maindoorkey = false;

        [SerializeField] private KeyInventory _keyInventory = null;

        private KeyDoorController doorObject;

        private void Start()
        {
            if (maindoor)
            {
                doorObject = GetComponent<KeyDoorController>();
            }
        }

        public void ObjectInteraction()
        {
            if (maindoor)
            {
                doorObject.PlayAnimation();
            }

            else if (maindoorkey)
            {
                _keyInventory.hasmaindoorkey = true;
                gameObject.SetActive(false);
            }

        }
    }
}

the following is interactive item inventory script

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

namespace KeySystem
{
    public class KeyInventory : MonoBehaviour
    {
        public bool hasmaindoorkey = false;
    }
}

the following is the interactive item raycast script

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

namespace KeySystem
{
    public class KeyRaycast : MonoBehaviour
    {
        [SerializeField] private int rayLength = 5;
        [SerializeField] private LayerMask layerMaskinteract;

        private KeyItemController raycastedObject;
        [SerializeField] private KeyCode openDoorKey = KeyCode.Mouse0;

        [SerializeField] private Image crosshair = null;
        private bool isCrosshairActive;
        private bool doOnce;

        private string interactableTag = "InteractiveObject";

        private void Update()
        {
            RaycastHit hit;
            Vector3 fwd = transform.TransformDirection(Vector3.forward);

            int mask = layerMaskinteract.value;

            if (Physics.Raycast(transform.position, fwd, out hit, rayLength, mask))
            {
                if (hit.collider.CompareTag(interactableTag))
                {
                    if (!doOnce)
                    {
                        raycastedObject = hit.collider.gameObject.GetComponent<KeyItemController>();
                        CrosshairChange(true);
                    }

                    isCrosshairActive = true;
                    doOnce = true;

                    if (Input.GetKeyDown(openDoorKey))
                    {
                        raycastedObject.ObjectInteraction();
                    }
                }
            }
            else
            {
                if (isCrosshairActive)
                {
                    CrosshairChange(false);
                    doOnce = false;
                }
            }
        }

        void CrosshairChange(bool on)
        {
            if (on && !doOnce)
            {
                crosshair.color = Color.red;
            }
            else
            {
                crosshair.color = Color.white;
                isCrosshairActive = false;
            }
        }
    }
}

also go through the vedio of speed tutor as well as the user1productions horror tutoril door vedio

and thanks for helping

Could you pls send me the Pickupscript or that which manages the key pickup i dont know if you forgot it but i dont find it.

the keyitemcontroller,keyraycast,keyinventory are the scripts necessary for the keypiikup you have to see the video before trying it soo iit will be more clear to you i have sent the video of speed tutor for the keys and for the drawer door i am using user1productions horror tutorial part 3 door system this is the video