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

public class FreeFallPlayer : MonoBehaviour

{
    float lastplayed;
    public AudioClip myclip;
    bool playing = false;
    AudioSource audio;
    private void Awake()
    {
        audio = GetComponent<AudioSource>();
        lastplayed = -1;
    }
    public void Play()
    {
        if (lastplayed == -1 /*|| Time.time - lastplayed > 10*/)
        {
            lastplayed = Time.time;
            GetComponent<AudioSource>().PlayOneShot(myclip);
            playing = true;
            Camera.main.GetComponent<AudioController>().FadeOut(false);
        }
    }

    private void Update()
    {
        if (playing && !audio.isPlaying)
        {
            GameObject.FindGameObjectWithTag("Levels").GetComponent<Levels>().ReloadScene();
        }
    }
}

