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