0
0

Hello,

I am a sound designer and not a programmer and I need help with scripting. I am trying to integrate FMOD into Unity’s Adventure Sample Game. I found where I need to script in fmod in the audio reactions script but I am not quite sure how. Was wonder if anyone could offer up any advice or the code I need to intergrate?

This is the current code: (How/what fmod scripts can replace this?)

Audio Reaction

using UnityEngine;

// This Reaction is used to play sounds through a given AudioSource.
// Since the AudioSource itself handles delay, this is a Reaction
// rather than an DelayedReaction.
public class AudioReaction : Reaction
{
public AudioSource audioSource; // The AudioSource to play the clip.
public AudioClip audioClip; // The AudioClip to be played.
public float delay; // How long after React is called before the clip plays.

protected override void ImmediateReaction()
{
    // Set the AudioSource's clip to the given one and play with the given delay.
    audioSource.clip = audioClip;
    audioSource.PlayDelayed(delay);
}
  • You must to post comments
0
0

Hi Monet,

To port over from the native Unity sound engine to FMOD Studio is fairly easy; if you wish to just play an event once you can use:

FMODUnity.RuntimeManager.PlayOneShot("path/to/event");

Or, if you require a bit more control over your audio, you can create the event and play, pause, or stop when required.

event = FMODUnity.RuntimeManager.CreateInstance("path/to/event");
event.start(); // Starts the event
event.setPaused(true); // Pauses the event
event.setPaused(false); // Unpauses the event
event.stop(FMOD_STUDIO_STOP_ALLOWFADEOUT); // Calls a non-immediate stop, allowing sounds still playing (such as reverb tails) to finish off before releasing.

However the example script you are using seems to require a delay before the event is played. This makes it a bit more difficult, but you can try something like this:

using UnityEngine;

// This Reaction is used to play sounds through a given AudioSource.
// Since the AudioSource itself handles delay, this is a Reaction
// rather than an DelayedReaction.
public class AudioReaction : Reaction
{
    /*
    public AudioSource audioSource; // The AudioSource to play the clip.
    public AudioClip audioClip; // The AudioClip to be played.
    */
    public string FMOD_OneShot; // Path to FMOD Studio event being used. Use this for PlayOneShot
    public float delay; // How long after React is called before the clip plays.
    public int secondsToWait = 10; // Set how long to wait before starting event. Defaults to 10 seconds

    void Start()
    {

    }

    IEnumerator playFMODEvent()
    {
        yield return new WaitForSeconds(secondsToWait);
        FMODUnity.RuntimeManager.PlayOneShot(FMOD_OneShot); // This will play the event once and discard it from memory when finished
    }

    protected override void ImmediateReaction()
    {
        // Set the AudioSource's clip to the given one and play with the given delay.
        /*
        audioSource.clip = audioClip;
        audioSource.PlayDelayed(delay);
        */
        StartCoroutine(playFMODEvent()); // Waits 10 seconds before playing event
    }
}

The playFMODEvent function is external to the FMOD integration but will wait 10 seconds (or however long you wish for) before starting the event.

Please see our Unity scripting starting guide for more information:
http://www.fmod.org/documentation/#content/generated/engine_new_unity/scripting.html

Thanks,
Richard

  • Monet Gardiner

    Thank you so much for responding Richard!
    I tried that script but kept getting errors with the IEnumerator. I made sure I entered every thing correctly but I am not sure why I keep getting an error code saying IEnumerator could not be found

    -Monet

  • Richard Simms

    Hi Monet,

    This is more a Unity issue than an FMOD one, so it would probably be best to check over on their forums. My only suggestion is to ensure that “using System.Collections” is at the top of your script.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.