Help With CombinatioLock Script!!!:(

I Need Help!!!:frowning:
I have this script that i want to modify, I would like to know how i can make that when it appears when i press “e” on the object that it’s attached, and leave when i press “Esc”
Also I would like to know how i can make that the animation that i have in my Chest (open animation), plays when the password is correct (1234)
Everything else it’s working (The display of buttons, the correct/incorrect combination sound, etc)

Here is the Script:

//The Animation Clip lines are not working, they show errors…

var currentCombination : int = 0;
var Chest : AnimationClip; //This Line is not working
var Sound1 : AudioClip;
var Sound2 : AudioClip;
private var correctCombination : int = 1234;
var buttonClickProgress : int;

function OnGUI() {
if(GUI.Button(Rect (450,200, 50, 50), “1”)){ ButtonWasClicked(1); }
if(GUI.Button(Rect (500,200, 50, 50), “2”)){ ButtonWasClicked(2); }
if(GUI.Button(Rect (550,200, 50, 50), “3”)){ ButtonWasClicked(3); }
if(GUI.Button(Rect (450,250, 50, 50), “4”)){ ButtonWasClicked(4); }
if(GUI.Button(Rect (500,250, 50, 50), “5”)){ ButtonWasClicked(5); }
if(GUI.Button(Rect (550,250, 50, 50), “6”)){ ButtonWasClicked(6); }
if(GUI.Button(Rect (450,300, 50, 50), “7”)){ ButtonWasClicked(7); }
if(GUI.Button(Rect (500,300, 50, 50), “8”)){ ButtonWasClicked(8); }
if(GUI.Button(Rect (550,300, 50, 50), “9”)){ ButtonWasClicked(9); }
if(GUI.Button(Rect (500,350, 50, 50), “0”)){ ButtonWasClicked(0); }
}

function ButtonWasClicked (buttonNmb : int) {

currentCombination += buttonNmb;
buttonClickProgress++;

if(buttonClickProgress < 4){
currentCombination *= 10;
}
else{
if(currentCombination == correctCombination){
Debug.Log(“You Opened the Combination lock!”);
buttonClickProgress = 0;
currentCombination = 0;

audio.PlayOneShot(Sound1);

animation.Play(Chest); //This Line is also not working

}
else{
Debug.Log(“Wrong Combination Code, reseting…”);
buttonClickProgress = 0;
currentCombination = 0;

audio.PlayOneShot(Sound2);

}
}
}

Did you look into the reference?

Play does not take an AnimationClip as parameter.

Also I dont believe that you even need a public AnimationClip variable declared in your script.

Thank you!, I’m new in animation so i didn’t knew that, also do you now how i can make that this appears in the screen only when i press “e” in the collider of my chest??, or close it with “Esc”?