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

34 lines
736 B
C#
Raw Normal View History

2021-05-17 18:02:55 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using FMOD.Studio;
using FMODUnity;
using UnityEngine;
using STOP_MODE = FMOD.Studio.STOP_MODE;
public class LoopySound : MonoBehaviour
{
[SerializeField]
[EventRef]
private string _sfx;
private EventInstance _sfxInstance;
void Awake()
{
_sfxInstance = RuntimeManager.CreateInstance( _sfx );
RuntimeManager.AttachInstanceToGameObject( _sfxInstance, transform, (Rigidbody)null );
}
private void OnEnable()
{
_sfxInstance.start();
}
private void OnDisable()
{
_sfxInstance.stop(STOP_MODE.IMMEDIATE);
}
}