Add plate spawning counter
This commit is contained in:
parent
9da447f835
commit
7a3073ea8a
13 changed files with 891 additions and 92 deletions
51
Assets/Scripts/Counters/PlatesCounter.cs
Normal file
51
Assets/Scripts/Counters/PlatesCounter.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue