Deleting an instance

I am wondering how to delete an instantiate()'d object from inside code. For example, in one object's code, i have

if (Input.GetButtonDown("Shield"))
{
    if (shielding == 0)
    {
        Instantiate(shieldobject,transform.position, transform.rotation);
        shielding = 1;
    }
} else {
    if (shielding == 1)
    {
    shielding = 0;
    }
}

And in my Shield prefab is a code file that goes like this:

function Update () {
    if(Input.GetButtonDown("Shield"))
    {
        Debug.Log("destroyed");
        Destroy(gameObject)
    }
}

But the shield clone doesn't delete itself. How can i have it delete itself?

When you `Instantiate()` an object, you can store it using something like this:

var newObject = Instantiate(shieldobject,transform.position, transform.rotation);

Then later when you want to destroy it, `Destroy(newObject)`

Alternatively you could control the destruction from the parent class like this:

var shield : GameObject;

function Update()
{
    if (Input.GetButtonDown("Shield"))
    {
        if (!shield)
        {
            shield = (GameObject)Instantiate(shieldobject,transform.position, transform.rotation);
        }
    }
    else
    {
        if (shield)
        {
            Destroy(shield);
        }
    }