using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoundInstanceScript : MonoBehaviour
{



    [FMODUnity.EventRef]
    public string soundInstance;
    public FMOD.Studio.EventInstance soundinstance;

    [SerializeField] private bool playOnEnable = false;

    void OnEnable()
    {
        if (playOnEnable)
        {
            PlaySound();
        }
    }

    public void OnDisable()
    {
        soundinstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);

        soundinstance.release();

        soundinstance.clearHandle();
    }

    public void PlaySound()
    {

        soundinstance = FMODUnity.RuntimeManager.CreateInstance(soundInstance);
        // FMODUnity.RuntimeManager.AttachInstanceToGameObject(musicInstance, GetComponent<Transform>(), GetComponent<Rigidbody>());
        soundinstance.start();
    }

    public void PauseSound(bool paused)
    {
        soundinstance.setPaused(paused);
    }

}