- Home /
How to add sound effects
I'm quite new to unity and I was wondering how to add sound effects. I'm making a 2d platform game kind of like super mario bros. I've added background music but now I want to add sound effects for when the player dies, when the player kills an enemy, when the player jumps, when the player picks up a star but I have no idea how to do it :/ Ive got the sound effects I'm just not sure how to make them play once something has happened :) thanks in advance
Answer by jmparavicini · Jan 29, 2015 at 12:27 AM
Hi Zombie666Killa
So First Make sure you have an audio Listener anywhere on the scene. Then Put an audioSource to the Object where you want the sound come from. And then you add this scrip to it:
#pragma strict
var Clip1 : AudioClip;
function Start () {
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.E))
{
audio.PlayOneShot(Clip1);
}
}
in the Inspector you will have to Put your clip into the Clip1 Space. You just have to change the if statement to whatever you want.
I Hope i could help if you have any question or something isnt clear please tell me. cheers skullbeats1