|
How do I add a sound when I fire a bullet with my weapon ? I've tried to add ''Audio Source'' but the sound just come automatically when I start. Anyone know How I can add the sound when I shoot ?
(comments are locked)
|
|
Sure, drag a sound file to the object, and in the audio source drop list, uncheck play on awake. To play sound in script, i have tried this but still get just sound at the start and not when im shooting ?
Mar 31 '12 at 02:56 PM
metalmutha11
(comments are locked)
|
|
Hey simpleone, i see that you want something simple :D (beacuse of name)... 1) You need to attach audio file to a player. 2) Uncheck Play On Awake. 3) Make JavaScript. 4) Copy this code to your script... function Update() { } 5) Attach script to a player. 6) Test and enjoy! Good Luck, Ivan.
(comments are locked)
|
|
Here is a more complete example, feel free to ask if you have any questions. Add this script to the gun. Make sure that the gun has an AudioSource component attached in the Inspector (this will happen automatically if you drag and drop your AudioClip to a GameObject in the scene) and that you have unchecked "Play On Awake". Example 1: The cut-offRemember that you also have When developing for desktop or devices that doesn't demand that you cache everything for performance (read iOS/Android) you most likely would like a more transparent approach where audio won't be cut off. This is easiest done with PlayClipAtPoint where a GameObject with an AudioSource attached will instantiate on every shot. This only requires that you have the AudioClip dragged and dropped to the variable Shot in the Inspector. Example 2: The transparent
(comments are locked)
|
