campfire/Assets/Scripts/CasettePickup.cs

57 lines
1.4 KiB
C#
Raw Normal View History

2020-04-21 01:55:24 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
2020-05-01 04:37:20 +02:00
[RequireComponent(typeof(PickupStatus))]
2020-04-21 01:55:24 +02:00
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;
}
}
private AudioSource Source;
2020-05-01 04:37:20 +02:00
private PickupStatus Pickup;
2020-04-21 01:55:24 +02:00
private void Awake() {
Source = GetComponent<AudioSource>();
2020-05-01 04:37:20 +02:00
Pickup = GetComponent<PickupStatus>();
2020-04-21 01:55:24 +02:00
CasetteProgress.CasetteCount = Clips.Length;
}
private void Update() {
2020-05-01 04:37:20 +02:00
if (Pickup.Grabbed) {
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-05-01 04:37:20 +02:00
Pickup.Grab();
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
}
}
2020-05-01 04:37:20 +02:00
private static CasettePickup PreviousPickup = null;
public void PickupVR() {
Play(PreviousPickup);
PreviousPickup = this;
}
2020-04-21 01:55:24 +02:00
}