campfire/Assets/Scripts/CasettePickup.cs

49 lines
1.2 KiB
C#

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