- Home /
Question by
tehdiamondpl · Jan 28, 2014 at 07:27 PM ·
2daudioplatformerplaywont
Audio won't play
Hey. I am trying to do some platformer 2D game, so i have my movement done yet, and i want to write script for picking up coins. Destroying object on collision works perfect but audio wont' play no matter what. Here's the code:
@script RequireComponent(AudioSource)
var clip : AudioClip;
function OnCollisionEnter2D(coll: Collision2D){
audio.PlayOneShot(clip, 1.0f);
Destroy(gameObject);
}
Comment
Answer by Xtro · Jan 28, 2014 at 08:00 PM
If the audio is on the gameObject, it's deleted too!
Put the audio onto another object or delay the destroy command with the duration parameter.
Can you please mark the correct answer if you fixed that problem?