GameVsJam/3d Prototyp/Assets/CoffeeMachine.cs

70 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Interaction;
using Microsoft.VisualStudio.RpcContracts.Logging;
using UnityEngine;
using Utility;
public class CoffeeMachine : MonoBehaviour
{
2024-04-07 17:30:22 +02:00
[SerializeField]
private AudioClip _buttonClick;
2024-04-09 01:17:44 +02:00
[SerializeField]
private AudioClip _deny;
[SerializeField]
private AudioClip _coffeeMachine;
2024-04-07 17:30:22 +02:00
[SerializeField]
private AudioSource _audioSource;
[SerializeField]
private List<CoffeePlace> _coffeePlaces = new();
[SerializeField]
private bool _isCooking = false;
[SerializeField]
private List<PickupInteractible> _coffeItemPrefabs = new();
public void CookCoffee()
{
2024-04-07 17:30:22 +02:00
_audioSource.PlayOneShot(_buttonClick);
if (_isCooking)
return;
_isCooking = true;
StartCoroutine(CookCoffeeRoutine());
}
private IEnumerator CookCoffeeRoutine()
{
2024-04-09 01:17:44 +02:00
yield return new WaitForSeconds(0.5f);
2024-04-09 01:17:44 +02:00
_audioSource.PlayOneShot(_coffeeMachine);
yield return new WaitForSeconds(7);
2024-04-09 01:17:44 +02:00
for (int i = 0; i < 2; i++)
{
2024-04-09 01:17:44 +02:00
CoffeePlace coffeePlace = _coffeePlaces.Where(c => c.IsFree()).ToList().GetRandomElement();
2024-04-09 01:17:44 +02:00
if (coffeePlace == null)
{
// TODO: Spill coffee
Debug.Log("misty kaki");
}
else
{
Instantiate(_coffeItemPrefabs.GetRandomElement(), coffeePlace.transform.position, Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0));
}
}
_isCooking = false;
}
}