44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class PlatesCounter : BaseCounter
|
|
{
|
|
[SerializeField] private float spawnPlateTimerMax = 10f;
|
|
[SerializeField] private int platesSpawnedAmountMax = 6;
|
|
[SerializeField] private KitchenObjectSO plateKitchenObjectSO;
|
|
private int platesSpawnedAmount;
|
|
private float spawnPlateTimer;
|
|
|
|
private void Update()
|
|
{
|
|
spawnPlateTimer += Time.deltaTime;
|
|
if (spawnPlateTimer > spawnPlateTimerMax)
|
|
{
|
|
spawnPlateTimer = 0f;
|
|
if (KitchenGameManager.Instance.IsGamePlaying() && platesSpawnedAmount < platesSpawnedAmountMax)
|
|
{
|
|
platesSpawnedAmount++;
|
|
// Debug.Log($"Spawning another plate {platesSpawnedAmount}/{platesSpawnedAmountMax}");
|
|
OnPlateSpawned?.Invoke(this, System.EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
|
|
public event EventHandler OnPlateSpawned;
|
|
public event EventHandler OnPlateRemoved;
|
|
|
|
public override void Interact(Player player)
|
|
{
|
|
if (player.KitchenObject == null)
|
|
{
|
|
// Player is empty handed
|
|
if (platesSpawnedAmount > 0)
|
|
{
|
|
// There is at least one plate here
|
|
platesSpawnedAmount--;
|
|
_ = KitchenObject.SpawnKitchenObject(plateKitchenObjectSO, player);
|
|
OnPlateRemoved?.Invoke(this, System.EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
} |