Added Cooldown to pooping
This commit is contained in:
@@ -309,6 +309,7 @@ MonoBehaviour:
|
|||||||
targetSpawner: {fileID: 1838778561}
|
targetSpawner: {fileID: 1838778561}
|
||||||
gameOverScreen: {fileID: 81231374}
|
gameOverScreen: {fileID: 81231374}
|
||||||
poopPrefab: {fileID: 5552423787977869117, guid: 066f9990a9b1f5547b387633d5d204c0, type: 3}
|
poopPrefab: {fileID: 5552423787977869117, guid: 066f9990a9b1f5547b387633d5d204c0, type: 3}
|
||||||
|
poopCooldown: 0.5
|
||||||
--- !u!4 &128829408
|
--- !u!4 &128829408
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ namespace Minigames.BirdPooper
|
|||||||
private int targetsHit;
|
private int targetsHit;
|
||||||
private bool isGameOver;
|
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()
|
internal override void OnManagedAwake()
|
||||||
{
|
{
|
||||||
base.OnManagedAwake();
|
base.OnManagedAwake();
|
||||||
@@ -156,12 +163,18 @@ namespace Minigames.BirdPooper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SpawnPoop()
|
public void SpawnPoop()
|
||||||
{
|
{
|
||||||
|
// enforce cooldown
|
||||||
|
if (Time.time < _lastPoopTime + poopCooldown)
|
||||||
|
return;
|
||||||
|
|
||||||
if (isGameOver || player == null || poopPrefab == null)
|
if (isGameOver || player == null || poopPrefab == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Vector3 spawnPosition = player.transform.position;
|
Vector3 spawnPosition = player.transform.position;
|
||||||
Instantiate(poopPrefab, spawnPosition, Quaternion.identity);
|
Instantiate(poopPrefab, spawnPosition, Quaternion.identity);
|
||||||
|
|
||||||
|
_lastPoopTime = Time.time;
|
||||||
|
|
||||||
Debug.Log($"[BirdPooperGameManager] Spawned poop at {spawnPosition}");
|
Debug.Log($"[BirdPooperGameManager] Spawned poop at {spawnPosition}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user