Group Group Group Group Group Group Group Group Group

There is no 'AudioSource' attached to the "SpaceMarine" game object

on page 179 of the book,

I add an audio source to the BobbleMarine-body

then add lines to the gun script.

when running the game I get

MissingComponentException: There is no ‘AudioSource’ attached to the “SpaceMarine” game object, but a script is trying to access it.
You probably need to add an AudioSource to the game object “SpaceMarine”. Or your script needs to check if the component is attached before using it.
UnityEngine.AudioSource.PlayOneShot (UnityEngine.AudioClip clip) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/Audio/AudioBindings.gen.cs:676)
Gun.fireBullet () (at Assets/Scripts/Gun.cs:18)

I added an audio source to the SpaceMarine GameObject and removed it from BobbleMarine-body.

which has fixed it.

1 Like