Added Cooldown to pooping
This commit is contained in:
@@ -309,6 +309,7 @@ MonoBehaviour:
|
||||
targetSpawner: {fileID: 1838778561}
|
||||
gameOverScreen: {fileID: 81231374}
|
||||
poopPrefab: {fileID: 5552423787977869117, guid: 066f9990a9b1f5547b387633d5d204c0, type: 3}
|
||||
poopCooldown: 0.5
|
||||
--- !u!4 &128829408
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -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