Last active
May 7, 2019 02:52
-
-
Save webthingee/143e71ab28a5e68fca2292be5c8b64e4 to your computer and use it in GitHub Desktop.
FMOD Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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