using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(AudioSource))] public class CasettePickup : MonoBehaviour { public AudioClip[] Clips; public string DisplayPrompt { get { return (PreviousInQueue != null && PreviousInQueue.Playing) ? "Queue casette" : "Play casette"; } } public bool Playing { get { return Source.isPlaying; } } public bool PickedUp = false; private AudioSource Source; private CasettePickup PreviousInQueue; private int WaitingIndex; private void Awake() { Source = GetComponent(); CasetteProgress.CasetteCount = Clips.Length; } private void Update() { if (PickedUp) { transform.localScale = Vector3.Lerp(transform.localScale, Vector3.zero, 10f * Time.deltaTime); } if (PreviousInQueue != null) { if (!PreviousInQueue.Playing) { PreviousInQueue = null; Source.PlayOneShot(Clips[WaitingIndex]); } else if (PreviousInQueue == null && !Source.isPlaying) { Destroy(gameObject); } } else if (CasetteProgress.AllCasettesPlayed && !Playing) { Destroy(gameObject); } } public void Play(CasettePickup previous) { PickedUp = true; int Index = CasetteProgress.PlayNext(); if (Index != -1) { if (previous == null) { Source.PlayOneShot(Clips[Index]); } else { PreviousInQueue = previous; WaitingIndex = Index; } } } }