i want to play sound when i pick/Destroy the coin. How would i do that? here is my code.
#pragma strict
var coinEffect : Transform;
var coinVaule = 1;
function OnTriggerEnter (info : Collider) {
if(info.tag == "Player"){
GameMaster.currentScore += coinVaule;
var effect = Instantiate(coinEffect, transform.position, transform.rotation);
Destroy(effect.gameObject, .4);
Destroy(gameObject);
}
}
add
audio.PlayOneShot(soundaudiofile);
add an audioSource and make a AudioClip soundaudiofile var.
I would do it this way:
After entering a trigger spawn an empty GameObject using instantiate.
//create a Sound Game Object and make it into a Prefab
//then create a var to hold it in.
var sound : Transform;
function OnTriggerEnter(theCollider : Collider){
if(theCollider.tag == "Player"){
Instantiate(sound, transform.position, transform.rotation);
}
}
I haven’t tested it but something like that should work.