54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlatesCounter : BaseCounter
|
|
{
|
|
|
|
public event EventHandler OnPlateSpawned;
|
|
public event EventHandler OnPlateRemoved;
|
|
|
|
[SerializeField] private float spawnPlateTimerMax = 4f;
|
|
[SerializeField] private KitchenObjectSO plateKitchenObjectSO;
|
|
|
|
private float spawnPlateTimer;
|
|
private int platesSpawnedAmount;
|
|
private int platesSpawnedMax = 4;
|
|
|
|
private void Update()
|
|
{
|
|
if (GameStateManager.Instace.IsGamePlaying())
|
|
{
|
|
spawnPlateTimer += Time.deltaTime;
|
|
}
|
|
if (spawnPlateTimer > spawnPlateTimerMax)
|
|
{
|
|
spawnPlateTimer = 0f;
|
|
|
|
if (GameStateManager.Instace.IsGamePlaying() && platesSpawnedAmount < platesSpawnedMax)
|
|
{
|
|
platesSpawnedAmount++;
|
|
|
|
OnPlateSpawned?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Interact(Player player)
|
|
{
|
|
if (!player.HasKitchenObject())
|
|
{
|
|
// player is empty handed
|
|
if (platesSpawnedAmount > 0)
|
|
{
|
|
// at least 1 plate on counter
|
|
platesSpawnedAmount--;
|
|
|
|
KitchenObject.SpawnKitchenObject(plateKitchenObjectSO, player);
|
|
|
|
OnPlateRemoved?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
}
|