Adding trick respawn logic
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user