campfire/Assets/Scripts/CasettePickup.cs

57 lines
1.4 KiB
C#

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