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