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);
}