What I want to happen is for a game object to be destroyed after 5 seconds only if the mouse is over the object and is held. Here is my script, which just doesn’t seem to work.
var wasClicked : boolean;
var endTime : float;
var timeLeft : int;
function OnMouseDown() {
wasClicked = true;
Activate();
}
function OnMouseUp() {
wasClicked = false;
Stop();
}
function OnMouseEnter() {
if (wasClicked) {
Activate();
}
}
function OnMouseExit() {
Stop();
}
function Activate() {
endTime = Time.time + 5.0;
timeLeft = endTime - Time.time;
if (timeLeft < 0)
{
Destroy(gameObject);
}
}
function Stop() {
endTime = 5.0;
}