mouse over enables another script

I am trying to make a script enable on mouse over, so that a specific menu will work only if the mouse is on that specific object. When the mouse is not on the object the same button does a different action. Having trouble so I thought I’d come to the community for help

Here is the code so far:
var rightclickworking : int = 0;

function OnMouseOver () {
rightclickworking = 1;
}

function OnMouseExit () {
rightclickguiworking = 0;
}

function Update () {
var script1 = GetComponent(“RightClick”);

if (rightclickworking == 1) {
script1.enabled = true;
}
else if (rightclickworking == 0) {
script1.enabled = false;    // <---- here is my issue
}

}

The error I am getting is: “Object reference not set to an instant of object” at line 15 and 18 where I specified.

This script is attached to the object and script1 is attached to the camera.
Could anybody help me with what I am doing wrong?

Directly calling GetComponent(RightClick) only allows you to access components on the same gameobject.

If you need to access to a component on another object, you must first have a reference to that gameobject and then use otherGameObject.GetComponent(RightClick).
Ideally you get that reference only once if the gameobject doesn’t change, e.g.:

var camera : GameObject; // assign in inspector
var script1 : RightClick;

function Awake() {
    script1 = camera.GetComponent(RightClick);
}

Sidenote: Just use booleans for flags instead of int:

var rightclickworking : boolean = false;
function OnMouseOver () { rightclickworking = true; }
function OnMouseExit () { rightclickguiworking = false; }

Now you can just do:

if (rightclickworking) {
    // ...
} else {
    // ...
}

… or just:

script1.enabled = rightclickworking;