This repository has been archived on 2025-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mojo-kitchen-chaos/Assets/Scripts/Counters/PlatesCounter.cs

51 lines
1.3 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()
{
spawnPlateTimer += Time.deltaTime;
if (spawnPlateTimer > spawnPlateTimerMax)
{
spawnPlateTimer = 0f;
if (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);
}
}
}
}