Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Are there any beginner tutorials about attaching sounds to objects in Unity?

Discussion in 'Audio & Video' started by Craft-Media-Group, Jun 18, 2015.

  1. Craft-Media-Group

    Craft-Media-Group

    Joined:
    Aug 21, 2014
    Posts:
    138
    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,
     
  2. Gnatty

    Gnatty

    Joined:
    May 17, 2012
    Posts:
    77
  3. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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.
     
  4. Craft-Media-Group

    Craft-Media-Group

    Joined:
    Aug 21, 2014
    Posts:
    138
    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?
     
  5. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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.
     
  6. Craft-Media-Group

    Craft-Media-Group

    Joined:
    Aug 21, 2014
    Posts:
    138

    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?
     
  7. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    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.
     
    Craft-Media-Group likes this.
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    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.
     
    blizzy, jerotas and Craft-Media-Group like this.