Unknown identifier

Hi there,
I’m trying to make an object (the object is named “dodecahedron”) animate by a player coming into a close proximity of said object - I was given this script earlier on.

var target : Transform;
var detectRange: float = 30;

function Update() {
    var tgtDirection = target.position - transform.position; 
 
    var tgtDistance = tgtDirection.magnitude;
    if (tgtDistance <= detectRange) {
        dodecahedron.animation.Play("Animation");
    }
}

HOWEVER when I try and input the code I get this message: “Assets/Proximity.js(8,1): BCE0005: Unknown identifier: ‘dodecahedron’.”

What am i doing wrong?

That is because you have never created a “dodecahedron” GameObject in your script.

I think you need to change your approach. You have this dodecahedron object right?

So attach to him a script like this

var player:GameObject;
var distance:int = 30;
var animNotPlayed:boolean;

function Start(){
   player = GameObject.Find("Player");  // Find the player
   animNotPlayed=true;
}

function Update(){
if(animNotPlayed){
    // Here I changed player.position to player.transform.position.
   if(Vector3.Distance(player.transform.position,transform.position)<distance){ // Check distance
      animation.Play("Animation");     //Play animation
      animNotPlayed=false;
}}}