revival/game/Assets/Scripts/Audio/SFXTrigger.cs

26 lines
576 B
C#

using FMOD.Studio;
using FMODUnity;
using UnityEngine;
using STOP_MODE = FMOD.Studio.STOP_MODE;
public class SFXTrigger : MonoBehaviour
{
[SerializeField]
[EventRef]
private string _sfx;
private EventInstance _sfxInstance;
void Awake()
{
_sfxInstance = RuntimeManager.CreateInstance( _sfx );
RuntimeManager.AttachInstanceToGameObject( _sfxInstance, transform, (Rigidbody)null );
}
public void Trigger()
{
_sfxInstance.stop(STOP_MODE.IMMEDIATE);
_sfxInstance.start();
}
}