Add Sound Effect – Unity3D (C#)
You can add sound effects for all actions in your project. For example, when your character jumps or collides another object or just click on a button, you can call your sound effect. At first, add an “Audio Source” to your scene. As you see in the picture, you can assign a audio file to it. Import your sound file and assign it. Now, open your character script or wherever you want to call it and write your code:
1 2 3 4 5 6 7 8 |
public AudioSource clickAudio; void OnCollisionEnter(Collision c) { if (c.gameObject.name == "Enemy") { clickAudio.Play (); } } |
Assign your audio source tu public clickAudio and test it. Now your sound effect is played when your character collides with game object named Enemy.
©Coffee Break Codes – Add Sound Effect – Unity3D (C#)
Thanks,
It is easy.
this is very helpful
thank you very much