Adding trick respawn logic

This commit is contained in:
hz
2026-01-31 22:03:18 -06:00
parent 36422bbbc6
commit e6593192a7
6 changed files with 74 additions and 3 deletions
+5
View File
@@ -42,6 +42,11 @@ public class Spawner : MonoBehaviour
}
}
public void SpawnNow()
{
SpawnOnce();
}
private IEnumerator SpawnRoutine()
{
// Infinite loop to keep spawning (can be modified)
+11
View File
@@ -11,6 +11,7 @@ public class TrickController : MonoBehaviour
private static readonly List<TrickController> ActiveTricks = new List<TrickController>();
private static PlayerPlatformerController[] cachedPlayers = Array.Empty<PlayerPlatformerController>();
private static float nextPlayerCacheTime;
public static int ActiveCount => ActiveTricks.Count;
[SerializeField] private string treatTag = "Interactable";
[SerializeField] private float moveSpeed = 3.5f;
@@ -30,6 +31,9 @@ public class TrickController : MonoBehaviour
[SerializeField] private float jumpChancePerSecond = 0.5f;
[SerializeField] private LayerMask groundMask = ~0;
[SerializeField] private float groundCheckDistance = 0.05f;
[SerializeField] private float despawnMinX = -12f;
[SerializeField] private float despawnMaxX = 12f;
[SerializeField] private float despawnMinY = -10f;
private Rigidbody2D body;
private Transform target;
@@ -74,6 +78,13 @@ public class TrickController : MonoBehaviour
return;
}
var position = transform.position;
if (position.x < despawnMinX || position.x > despawnMaxX || position.y < despawnMinY)
{
Destroy(gameObject);
return;
}
if (Time.time >= nextTargetTime)
{
target = FindNearestTreat();
+27
View File
@@ -0,0 +1,27 @@
using UnityEngine;
public class TrickSpawnKeeper : MonoBehaviour
{
[SerializeField] private Spawner spawner;
[SerializeField] private float checkInterval = 1f;
private float nextCheckTime;
private void Update()
{
if (Time.time < nextCheckTime)
{
return;
}
nextCheckTime = Time.time + checkInterval;
if (spawner == null)
{
return;
}
if (TrickController.ActiveCount == 0)
{
spawner.SpawnNow();
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4eb1753179e848ed8662b6f039a33df9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: