Glich with treasure chest

I made a treasure chest that you find and you open it with a raycast, but the problem I have is after its open, if your raycast hits it the animation plays again. Its pretty stupid looking and i don't no how to fix it. This iss my code so far(only the important parts):

function Update ()
{
    var hit : RaycastHit;
    if (Physics.Raycast(transform.position, transform.forward, hit, 5))
    {
        if(hit.collider.gameObject.tag == "chest")
        {
            hit.collider.gameObject.animation.Play("chestOpen");

        }
    }
}

The solution is to remember the event of opening the chest, and only do the raycast test if the chest was not previously opened. For instance, you could have a

var chestOpened = false;

as an instance variable of that script, then do

chestOpened = true;

when you open the chest (just before the Play("chestOpen") call), and finally, surround the entire raycast check with the following check:

if (!chestOpened) {

// Raycast

}

Of course, since your game will likely have more things to interact with than a single chest, you will probably have to think up a more sophisticated way of tracking events than simple boolean variables, but this should solve your immediate problem.