OnMouseEnter problem,OnMouseOver True

Hello, i just started unity about a month ago, and I’m currently making a horror game. I have a working door script, but I wanted to make it so it only opened when the mouse was on the door. When I put the OnMouseOver function as a argument for door opening, it no longer works. Maybe i’m missing something obvious? Help would be appreciated! Here’s my door script code

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

public class DoorInteract : MonoBehaviour
{
public float TheDistance;
public bool doorOpen;
public bool MouseOver;
public GameObject Player;
public GameObject Door;
private Animation anim;

void Start(){

    doorOpen = false;
    
}

void Update()
{
    TheDistance = Vector3.Distance(Player.transform.position, Door.transform.position);

    anim = gameObject.GetComponent<Animation>();

    

        if (doorOpen == false && MouseOver == true)
        {

            if (TheDistance <= 2 && Input.GetKeyDown(KeyCode.F))
            {

                doorOpen = true;

                anim.Play("dooropen1");

            }
        }
        else if (doorOpen == true && MouseOver == true)
        {

            if (TheDistance <= 2 && Input.GetKeyDown(KeyCode.F))
            {

                doorOpen = false;

                anim.Play("doorclose1");

            }
        }

    }


void OnMouseOver(){



    MouseOver = true;
  

    
}

void OnMouseExit(){



    MouseOver = false;
    
   

    

}

}

,Hello, I just started using Unity not too long ago. I have a problem with a door script. The door works perfectly fine without OnMouseOver, but when I try to make it work only when the mouse is on it, it won’t work at all. Maybe i’m just missing something obvious. Help would be appreciated! My doorinteract script is below.

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

public class DoorInteract : MonoBehaviour
{
public float TheDistance;
public bool doorOpen;
public bool MouseOver;
public GameObject Player;
public GameObject Door;
private Animation anim;

void Start(){

    doorOpen = false;
    
}

void Update()
{
    TheDistance = Vector3.Distance(Player.transform.position, Door.transform.position);

    anim = gameObject.GetComponent<Animation>();

    

        if (doorOpen == false)
        {

            if (TheDistance <= 2 && Input.GetKeyDown(KeyCode.F))
            {

                doorOpen = true;

                anim.Play("dooropen1");

            }
        }
        else if (MouseOver == false && doorOpen == true)
        {

            if (TheDistance <= 2 && Input.GetKeyDown(KeyCode.F))
            {
                doorOpen = false;

                anim.Play("doorclose1");

            }
        }

    }

void OnMouseOver(){

    MouseOver = true;
  


    
}

void OnMouseExit(){

 

    MouseOver = false;
    
   


}

}

The script itself looks OK. So I’ll mention that in order for the OnMouseOver function to work, the GameObject that has this script MUST have a collider component of some sort. I’d suspect a “BoxCollider” would work for a door.

Note: if the collider is a “trigger” (a checkbox on the collider component), it will NOT be detected by MouseOver() unless the Physics.queriesHitTriggers (a global boolean value) is set to true.