Hi,
I’m looking for a series or youtube channel that lays out the steps for hooking up audio to objects in Unity. I’m mostly curious; does one need to script ever event in Unity or can you just assign a sound emitter to an object similar to Unreal, with no scripting or coding involved.
Thanks,
Will these help?
I don’t know anything about Unreal, but yes, you can, by simply adding an AudioSource component to your object. But that doesn’t make it play when you want it to.
So instead of a GUI or other controls, every time you want a sound to play in Unity you have to manually script the event?
How would Unity know when you want to play a sound? For example, Unity doesn’t have a concept of “player presses the fire button → gun makes sound.” You need a way to tell Unity to actually play that sound, and that is usually done through scripting. Of course there might be extensions to Unity that enable you to do that via the GUI, but under the hood, they all do the same.
But maybe I’m just not quite understanding what you are trying to achieve? Perhaps you can elaborate a bit more on that.
For example, in Unreal, each weapon has a “fire state” where you can attach a sound when it fires (these are options in the weapon object) or vehicles have various “states” like “idle” “reverse” and collidable objects have things like “impact” or “destroy” states. Is there nothing like this in Unity?
Since there is no “weapon script” provided by Unity, I’d say not. One of the problems with attaching an AudioSource to an enemy is that you can’t play its death sound with it because when it gets destroyed or despawned right after that, the sound will abruptly stop.
However with plugins such as our Master Audio (link in signature), this is easily done with a single line of code for non-MonoBehavior events such as “reverse”. Impact and Destroy can be done with zero coding since those are Unity MonoBehavior events (OnTrigger and OnDisable technically). Our design gets around problems like the above.
Note that you can cause audio sources to play using the UnityEvent system, if you’re working with a script that supports it. At the moment the only scripts built into Unity that use the UnityEvent system are the UI system scripts. So you could have a UI button that, when clicked, automatically plays an AudioSource (as well as doing other things) without writing any code.