From b5bd863822a752d42c211420c879d8e91b6518ef Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Tue, 21 Apr 2020 03:01:37 +0300 Subject: [PATCH] Add PickedUp to casette --- Assets/Scripts/CasettePickup.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/CasettePickup.cs b/Assets/Scripts/CasettePickup.cs index 56548df..b635a4c 100644 --- a/Assets/Scripts/CasettePickup.cs +++ b/Assets/Scripts/CasettePickup.cs @@ -15,20 +15,19 @@ public class CasettePickup : MonoBehaviour { return Source.isPlaying; } } + public bool PickedUp = false; private AudioSource Source; private CasettePickup PreviousInQueue; private int WaitingIndex; - private bool Disappear; private void Awake() { Source = GetComponent(); CasetteProgress.CasetteCount = Clips.Length; - Disappear = false; } private void Update() { - if (Disappear) { + if (PickedUp) { transform.localScale = Vector3.Lerp(transform.localScale, Vector3.zero, 10f * Time.deltaTime); } @@ -36,6 +35,8 @@ public class CasettePickup : MonoBehaviour { if (!PreviousInQueue.Playing) { PreviousInQueue = null; Source.PlayOneShot(Clips[WaitingIndex]); + } else if (PreviousInQueue == null && !Source.isPlaying) { + Destroy(gameObject); } } else if (CasetteProgress.AllCasettesPlayed && !Playing) { Destroy(gameObject); @@ -43,9 +44,9 @@ public class CasettePickup : MonoBehaviour { } public void Play(CasettePickup previous) { + PickedUp = true; int Index = CasetteProgress.PlayNext(); if (Index != -1) { - Disappear = true; if (previous == null) { Source.PlayOneShot(Clips[Index]); } else {