Interact with near object while the player is looking at it

Hi everyone. I have it mostly done, except for this one bug.

I have a boolean called, isInteracting which starts obviously as false.

If I’m inside a certain range from the target object, I begin shooting rays to colliders looking for that object’s tag, if I look at it, isInteracting equals true.
The issue I have is that if I keep looking at it and leave the range, the isInteracting does not come back to false.

By now, I know it’s because the player is always in contact other collider (the ground) and because of that, I cannot set isInteracting to false when the player is not in the range of the target collider, because its always happening!

Any help is really appreciated

Player interact class code:

public bool isInteracting;
   
    // Update is called once per frame
    void FixedUpdate()
    {
        // Check for nearby colliders looking for the parchment.

        Collider[] colliderArray = Physics.OverlapSphere(transform.position, interactRange);
        foreach (Collider collider in  colliderArray)
        {
            Debug.Log(collider.tag);
            if (collider.tag == "parchment")
            {
                // Shoot a ray when in range to make sure the player is looking at it.

                Debug.Log("1");
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out RaycastHit hit))
                {
                    if (hit.collider.tag == "parchment")
                    {
                        Debug.Log("2");
                        isInteracting = true;
                        Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow, 1.0f);
                    }
                    else
                    {
                        Debug.Log("3n");
                        isInteracting = false;
                    }
                }      
            }
           
        }
    }

The only part of your code that sets isInteracting to false is inside the foreach, AND inside the first if condition, AND inside the second if condition. It would seem you want to set isInteracting false whenever ANY of these conditions fail.

Instead of lines 27~31, just insert isInteracting = false; above line 6. This will make it assume that interaction is false on every update, UNLESS all of these other conditions happen to succeed.

Oh, clearly a logical error. That was it, thank you for your help!