Rasing and Lowering Object by clicking it

Hello, all.

I have a script with which I intend to click on a game object and raise it to a certain point. Then when I click on it again, it lowers it back to its previous position. By creating variables for it to “Lerp to” ( empty game objects as “targets”) I have succeeded in raising and lowering it in another script by using GetButton and it worked perfectly. Now I am trying to achieve the exact same goal by using the mouse and I am having NO such luck.
When I click on the object it raises a small increment of distance and then reverts back as soon as I let go of the mouse button. I am including the script for you to rip apart, just please don’t rip me apart as I am much less than an novice with this. I would GREATLY appreciate any help with this and thank you in advance.

var liftSpeed: float = 1; 
var target : GameObject;
var target2 : GameObject;
var wasClicked : boolean;

function OnMouseDown() {
    wasClicked = true;
    Activate();
}

function OnMouseUp() {
    wasClicked = false;
    Deactivate();
}

function OnMouseEnter() {
    if (wasClicked) {
        Activate();
    }
}

function OnMouseExit() {
    Deactivate();
}

function Activate() {
    transform.position = Vector3.Lerp(transform.position, target.transform.position, Time.deltaTime * liftSpeed);
}

function Deactivate() {
    transform.position = Vector3.Lerp(transform.position, target2.transform.position, Time.deltaTime * liftSpeed);
}

I guess it’s because the Activate function (or deactivate), which contains the lerp function is called only when you have the OnMouseDown, OnMouseUp or OnMouseEnter event

Easiest way would be to call the lerp functions in the Update() function according to a boolean store (as you did) when the event are triggered.

I’m not capable of testing this, however I think you should try this:

public float liftSpeed = 1.0; 
public Transform tUp;
public Transform tDown;
public boolean active = false;
 
function OnMouseDown() {
    active = !active;
}
 
function Update(){
    if(active){
        if(transform.position != tDown)
            transform.position = Vector3.Lerp(transform.position,tDown,Time.deltaTime*liftSpeed);
    }else{
        if(transform.position != tUp)
            transform.position = Vector3.Lerp(transform.position,tUp,Time.deltaTime*liftSpeed);
    }
}

Should work… might need to change a few things around.

Thanks. I will work with this and get back with you. I appreciate your time and help.