topical media & game development
lib-unity-book-06-CoconutCollision.js / js
/* Script Provided by Will Goldstone as part of Unity Game Development Essentials book assets */
/* Please Do Not Remove this comment - this script is for reference only */
var targetRoot : GameObject;
private var beenHit : boolean = false;
private var timer : float = 0.0;
var hitSound : AudioClip;
var resetSound : AudioClip;
function OnCollisionEnter(theObject : Collision) {
if(beenHit==false && theObject.gameObject.name=="coconut"){
audio.PlayOneShot(hitSound);
targetRoot.animation.Play("down");
beenHit=true;
CoconutWin.targets++;
}
}
function Update(){
if(beenHit){
timer += Time.deltaTime;
}
if(timer > 3){
audio.PlayOneShot(resetSound);
targetRoot.animation.Play("up");
beenHit=false;
CoconutWin.targets--;
timer=0.0;
}
}
@script RequireComponent(AudioSource)
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.