Enable Animation on Player reach area

I am having trouble enabling an animation after a player reaches a certain part of the level. I am working with this script that I attached to the Player object, but I got an error when I ran it. Here’s the current script, though it doesn’t work.

var target : Transform;
function Update () {
var other = animation.Play("gate3");
if ( Vector3.Distance(target.position, transform.position ) < 12) {
other.enabled = true;
}
if ( Vector3.Distance(target.position, transform.position ) > 12) {
other.enabled = false;
}
}


    appreciate any help!

First off: if you have an error-message, it’s usually a good idea to post that. People might tell what’s your problem is about, based on what it’s saying…

I’m still very new myself, but I think animation.Play() returns a boolean-value (true or false). This gets stored in your ‘other’ variable. Then you try to enable or disable the boolean. That doesn’t work of course.

have you tried this?

if (blah) {animation.Play();}
if (blah) {animation.Stop();}

Greetz, Ky.

Very much appreciated. Thank you! It works perfectly. Here is the full functional script for those who may need it:

var target : Transform;
var animationClip;
function Update () {
if ( Vector3.Distance(target.position, transform.position ) < 90) {
animation.Play();}
if ( Vector3.Distance(target.position, transform.position ) > 90) {
animation.Stop();}
}

One more question, though. How would I do the same for audio? So far I have a script that says:

var target : Transform;
var audiosource;
function Update () {
if ( Vector3.Distance(target.position, transform.position ) < 200) {
audio.Play();}
if ( Vector3.Distance(target.position, transform.position ) > 200) {
audio.Stop();}
}

but it doesn’t enable the audio. any suggestions? thanks again!