Collect 6 coins, Door animates

Hi,

I have a simple coin collecting script, in each level the Player collects 6 coins and then the exit opens. This I want to be done by animation and sound. I have tried so many ways and I just can’t seem to wrap my head around it. The animation is called ‘gardenexitanim’

coin script…

var coins : float;

function OnTriggerEnter( other : Collider ) {
    if (other.tag == "coin") {
        coins += 1; // or however many points you want to give per coin
        Destroy(other.gameObject);
    }
}

function OnGUI () {

        GUI.Label (Rect (20, 20, 200, 40), coins + "");

    }

Could someone give me some guidance please?

Thank you so much in advance!!

Unless I’m missing somthing, I think it can be done like this:

Create an int parameter in the door animator controller called e.g. coinCount.
Make a transition from the idle (or whichever) animation to gardinexitanim, and set the condition to be coinCount greater 5. This will trigger the transition when coinCount reaches 6.
In a script on the door:

private Animator animator;

void Start(){
	animator = GetComponent<Animator> ();
}
    
void Update(){
	animator.SetInteger("coinCount", coins);
}

You’ll have to access the coins variable from whichever script you were quoting in your question.