- Home /
How do you trigger audio once in unity 2d?
I'm a beginner trying to make a basic platformer game and can't find any good tutorials on this subject, any tips?
You can do so by using an Audio Source. Calling AudioSource.PlayClipAtPoint() plays an audio clip in world space, so its volume will be scaled based on how far away an audio listener is from it. AudioSource.PlayClipAtPoint() plays an audio clip without taking world space into account, so its volume will always be the same.
Answer by sevalk · Nov 15, 2020 at 11:49 AM
[SerializeField] AudioClip DeathSound;
[SerializeField] [Range(0, 1)] float DeathSoundVolume = 1;
private void OnTriggerEnter2D(Collider2D collision)
{
AudioSource.PlayClipAtPoint(DeathSound,Camera.main.transform.position, DeathSoundVolume);
}
Do you want music that will play as long as the game continues, or you want instant music that will play when an object is destroyed? If you can give a little more detail, I can help you better.
Your answer
![](https://koobas.hobune.stream/wayback/20220613015815im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Level design clone of King of Thieves 0 Answers
2D Platformer multiple spawnpoints 2 Answers
Timer jitters? SOLVED 0 Answers
Destroy a gameObject in the scene if instantiate the same gameObject 0 Answers
Problem with Jump 1 Answer