In process of getting game in development to work with unity, a few questions

Hey guys, I’m trying to convert one of the games I’m working on to work with fmod. As it stands, all of the sounds and music are currently being played using Unity’s audio engine, and I’m having trouble figuring out how the playoneshot works. is there any good documentation or tutorial I could use to get myself and my team familiarized with fmod with unity?"

like for example, i have a 2D sound i want to play which is assigned to the master bank. I want it to play whenever it is called in script, but I want to play in accordance with the game’s speed (if the game slows down, it slows down as well / if the game is paused, the sound is paused as well).

Currently the script is this:

using UnityEngine;
using System.Collections;

public class Lightning : MonoBehaviour {

public AudioClip[] thunderSounds = new AudioClip[4];
private bool flashing = true;
// Use this for initialization
void Start()
{
    StartCoroutine(Flash());

}

// Update is called once per frame
void Update()
{
    if (!GamePlay.paused)
    {
        GetComponent<AudioSource>().pitch = Time.timeScale;
        if (flashing)
        {
            if (GetComponent<Light>().range > 0)
                GetComponent<Light>().range -= Time.timeScale;
        }
        else
        {
            GetComponent<Light>().range = 80;
            GetComponent<Light>().enabled = true;
            flashing = true;
            GetComponent<AudioSource>().PlayOneShot(thunderSounds[Random.Range(0, thunderSounds.Length)], Global.GameSound);
        }
    }
}

IEnumerator Flash()
{
    while (true)
    {
        yield return new WaitForSeconds(Random.Range(0f, 20f));
        flashing = false;
    }
}

}

what would I do to make it so that the script plays the fmod sound effect instead of the sound effect it already has?

Hi William,

You would just change this line:

GetComponent<AudioSource>().PlayOneShot(thunderSounds[Random.Range(0, thunderSounds.Length)], Global.GameSound);

To use the FMOD Unity integration:

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

You can find more information on using FMOD with Unity in our documentation, and we have a few YouTube series on this as well:

https://www.fmod.com/resources/documentation-api?page=content/generated/engine_new_unity/scripting.html#/

Thanks,
Richard

Hi William,

To add what I wrote previously, in order to adjust the pitch of the event, you will need to create a parameter in the event and automate the master track’s pitch to it. PlayOneShot() will also not work with parameters, so you will first need to create the thunder event instance:

thunderEvent = FMODUnity.RuntimeManager.CreateInstance("event:/path/to/event");

Then you can replace:

GetComponent<AudioSource>().pitch = Time.timeScale;

With:

thunderEvent.setParameterValue(Time.timeScale);

And play it when you need in place of the PlayOneShot line.

Thanks,
Richard