Question by
VillainsParadise · Oct 19, 2020 at 10:39 PM ·
unity 2dprefabsaudiosourceshooting
[Unity2D] Adding Sound to a Prefab
In my shooting game, I'm trying to add an Audio Source to a bullet prefab. The script is set up so that when a bullet collides with an enemy it'll play the Audio Source;
When I add the Audio file to the inspector and drag it into the 'Impact Sound' field it looks normal.
But once it becomes a prefab...
the Audiosource is no longer there and when i run the game, and shoot the bullet at an enemy the game view freezes and Displays this message: "ArgumentNullException: Value cannot be null" and points to the "impactSound.play(); in the script.
how can I correct this error and achieve the effect I'm looking for?
bullet-script.png
(16.7 kB)
after-prefab.png
(4.9 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613014146im_/https://answers.unity.com/themes/thub/images/avi.jpg)