- Home /
Question by
paco morales · Oct 22, 2012 at 12:24 AM ·
collisiontarget
"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
capture01.jpg
(302.5 kB)
capture02.jpg
(276.2 kB)
Comment
Answer by Sundar · Oct 23, 2012 at 07:40 PM
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.