
using UnityEngine;

public class AudioManager : MonoBehaviour
{
    [SerializeField] GameObject jumpscare;

    private float waitTillNotActive = 0;

    public static AudioManager instance;
    private void Awake()
    {
        if (instance == null) { instance = this; jumpscare.SetActive(false); }
        else { Destroy(gameObject); }
            DontDestroyOnLoad(gameObject);
    }

    // Update is called once per frame
    void Update()
    {
        waitTillNotActive += Time.deltaTime;

        if (waitTillNotActive > 0.45)
        {
            jumpscare.SetActive(false);

            if (Random.Range(0f, 3000f) < 0.1)
            {
                waitTillNotActive = 0;
                jumpscare.SetActive(true);
                jumpscare.GetComponent<AudioSource>().Play();
                jumpscare.GetComponent<Animator>().Play("scare");
                Debug.Log("guess we doin jumpsacre now");
            }
        }
    }
}
