How to SetActive mesh only when Mouse Button is being held down

The “forcefield” mesh is a child of the object this script is attached to. Im trying to have the forcefield mesh enabled only when the right mouse button is down and disabled when the button is not being pressed. It flickers on and off because I assume the code is being checked each frame and not working properly and i cant figure out how to make it work. First I tried simply:

void Update ()
{
if(Input.GetKey(KeyCode.Mouse1))
{
transform.FindChild (“ForceField”).gameObject.SetActive (true);
}else{
transform.FindChild (“ForceField”).gameObject.SetActive (false);
}
}

That didn’t work so I tried using some bools:

private bool enabled = false;

void Update ()
{
if(!enabled)
{
if(Input.GetMouseButtonDown(1))
{
transform.FindChild (“ForceField”).gameObject.SetActive (true);
enabled = true;
}
}else if(Input.GetMouseButtonUp(1))
{
transform.FindChild (“ForceField”).gameObject.SetActive (false);
enabled = false;
}
}

Still flickering occasionally. What am i doing wrong?

Let me know if the code is spaced oddly in the message, I’ll try and rewrite it.

I dont work with C#, but i can try something in java,

var amienabled : boolean = true;

function Update(){

if(amienabled == true){
    renderer.enabled = true;
} else if(amienabled == false){
    renderer.enabled = false;


if(input.onkeydown(Keycode.Mouse0)){
    amienabled = true;
}
if(input.onkeyup(Keycode.Mouse0)){
    amienabled = false;
}

}