Skip to content

Instantly share code, notes, and snippets.

@webthingee
Last active May 7, 2019 02:52
Show Gist options
  • Save webthingee/143e71ab28a5e68fca2292be5c8b64e4 to your computer and use it in GitHub Desktop.
Save webthingee/143e71ab28a5e68fca2292be5c8b64e4 to your computer and use it in GitHub Desktop.
FMOD Studio
using FMODUnity;
using UnityEngine;
public class MainMusic : MonoBehaviour
{
[EventRef] public string mainMusicSelection;
private FMOD.Studio.EventInstance mainMusicEvent;
public float songSelectionValue;
void Start()
{
mainMusicEvent = RuntimeManager.CreateInstance(mainMusicSelection);
mainMusicEvent.setParameterByName("SongSelection", 0, true);
mainMusicEvent.start();
mainMusicEvent.release();
}
public void ChangeSongSelection(float songNum)
{
mainMusicEvent.setParameterByName("SongSelection", songNum, true);
songSelectionValue = songNum;
}
void Update()
{
mainMusicEvent.setParameterByName("SongSelection", songSelectionValue, true);
}
void Once()
{
RuntimeManager.PlayOneShotAttached("event:/SFX/...", gameObject);
RuntimeManager.PlayOneShot("event:/SFX/...", new Vector3(1f, 1f, 1f));
}
private void OnDestroy()
{
mainMusicEvent.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
}
}
Start()
shakeSoundEvent = RuntimeManager.CreateInstance("event:/SFX/BasicShake");
shakeSoundEvent.set3DAttributes(RuntimeUtils.To3DAttributes(transform));
Trigger()
// Play a sound when during changes
PLAYBACK_STATE playbackState;
shakeSoundEvent.getPlaybackState(out playbackState);
if (playbackState != PLAYBACK_STATE.PLAYING)
{
shakeSoundEvent.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment