campfire/Assets/Scripts/CasettePickup.cs

49 lines
1.2 KiB
C#
Raw Permalink Normal View History

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