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
+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();