Added Cooldown to pooping
This commit is contained in:
@@ -24,6 +24,13 @@ namespace Minigames.BirdPooper
|
||||
private int targetsHit;
|
||||
private bool isGameOver;
|
||||
|
||||
[Header("Input")]
|
||||
[Tooltip("Minimum seconds between consecutive poop spawns")]
|
||||
[SerializeField] private float poopCooldown = 0.5f;
|
||||
|
||||
// timestamp of last poop spawn
|
||||
private float _lastPoopTime = -Mathf.Infinity;
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
@@ -156,11 +163,17 @@ namespace Minigames.BirdPooper
|
||||
/// </summary>
|
||||
public void SpawnPoop()
|
||||
{
|
||||
// enforce cooldown
|
||||
if (Time.time < _lastPoopTime + poopCooldown)
|
||||
return;
|
||||
|
||||
if (isGameOver || player == null || poopPrefab == null)
|
||||
return;
|
||||
|
||||
Vector3 spawnPosition = player.transform.position;
|
||||
Instantiate(poopPrefab, spawnPosition, Quaternion.identity);
|
||||
|
||||
_lastPoopTime = Time.time;
|
||||
|
||||
Debug.Log($"[BirdPooperGameManager] Spawned poop at {spawnPosition}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user