"Target Collision" script. coconut

I have several weeks taking the book (Game Development Essentials), but now I’m stuck, with the “Target Collision” script.

Yesterday I saw the erratas book and I found out that someone else has the same problem and he solve it the same problem so I took his script but nothing happens.

I did exactly as the book said.

Please see my screenshots and the script. is there any errors?


#pragma strict

private var beenHit : boolean = false;
private var targetRoot : Animation;
var hitSound : AudioClip;
var resetSound : AudioClip;
var resetTime : float = 3.0;

function Start() {
targetRoot = transform.parent.transform.animation;
}
function OnCollisionEnter(theObject : Collision){
if (beenHit==false && theObject.gameObject.name=="coconut"){
StartCoroutine("targetHit");
}
}

function targetHit(){
audio.PlayOneShot(hitSound);
targetRoot.Play("down");
beenHit=true;

yield new WaitForSeconds(resetTime);

audio.PlayOneShot(resetSound);
targetRoot.Play("up");
beenHit=false;
}
@script RequireComponent(AudioSource)

Thanks

The one that caught my eyes is that you have written “yield new WaitForSeconds(resetTime)”, since you are using unityscript is it not “yield WaitForSeconds(resetTime)”.

If this did not solve your problem you need to tell what is not working in this script.