Problem with destroying object

The object doesn’t destroy with the second click. Can anyone help me understand what I’m doing wrong?

#pragma strict
var charBalloon1 : GameObject;
var position : Vector3;
var click : boolean = false;

function Start () {

}

function Update () {

}

function OnMouseDown () {
if (click == false) {
var cloneBalloon = Instantiate(charBalloon1, position, transform.rotation);
click = true;
}
else {
Destroy(cloneBalloon);
click = false;
}
}

Not sure exactly what your question is but here’s my best guess at an answer:
The variable ‘cloneBalloon’ is local to the OnMouseDown function, so it won’t persist between calls. Try making it a member variable instead.

Thanks, i’m gonna try it!

Not really sure how to do that actually… I’m pretty new to this…

You move the ‘var cloneBalloon’ bit out of the function. Like this:

#pragma strict
var charBalloon1 : GameObject;
var position : Vector3;
var click : boolean = false;
var cloneBalloon : Object; // Now a member variable

function Start () {

}

function Update () {

}

function OnMouseDown () {
  if (click == false) {
    cloneBalloon = Instantiate(charBalloon1, position, transform.rotation);
    click = true;
  }
  else {
    Destroy(cloneBalloon);
    click = false;
  }
}