Search Results for

    Show / Hide Table of Contents

    Sound Effect

    The SoundEffect script interfaces with an audio source to perform common tricks to create more varied sound effects. It is designed to add features to Unity's built-in AudioSource component:

    Sound Effect Fields

    Note that an audio clip doesn't have to be added into the audio source for SoundEffect to work: the script will automatically choose a random clip from the clip variations list and set the audio source's clip. That said, if a clip has been added to the attached audio source, that will be added to the clip variations list on script awake, with a default Frequency of one. Lastly, most adjustments made to the attached audio source -- besides volume and pitch, if Mutate Volume and Mutate Pitch fields are checked, respectively -- will affect the sound played by SoundEffect, including all the overlapping sound effects generated by this script.

    Using the sound effect script in code is pretty simple:

    using System.Collections;
    using UnityEngine;
    using OmiyaGames.Audio;
    
    public class TimeEffectsExample : MonoBehaviour
    {
        [SerializeField]
        SoundEffect testSound;
    
        IEnumerator Start()
        {
            // Setting up audio manager so the sound effect will play at the right volume
            yield return AudioManager.Setup();
    
            // Play a random clip in the clip variations list
            testSound.Play();
        }
    }
    

    Also, sound effect can be directly added into the hierarchy via the Create... menu, both in the hierarchy window, and right-click context menu. This method has the added benefit of setting the audio source's output to the mixer group set in the Sound Effects settings under Audio Manager's Project Settings:

    Create Sound Effect

    • Improve this Doc
    In This Article
    Back to top Copyright © 2022 Omiya Games