Adding trick respawn logic
This commit is contained in:
@@ -184,7 +184,7 @@ MonoBehaviour:
|
|||||||
targetRefreshInterval: 0.4
|
targetRefreshInterval: 0.4
|
||||||
consumeDistance: 0.35
|
consumeDistance: 0.35
|
||||||
wanderInterval: 1.2
|
wanderInterval: 1.2
|
||||||
consumeCooldown: 5
|
consumeCooldown: 3
|
||||||
trickPrefab: {fileID: 700000005}
|
trickPrefab: {fileID: 700000005}
|
||||||
avoidPlayerRadius: 0
|
avoidPlayerRadius: 0
|
||||||
avoidTrickRadius: 0
|
avoidTrickRadius: 0
|
||||||
@@ -200,3 +200,6 @@ MonoBehaviour:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 4294967295
|
m_Bits: 4294967295
|
||||||
groundCheckDistance: 0.05
|
groundCheckDistance: 0.05
|
||||||
|
despawnMinX: -12
|
||||||
|
despawnMaxX: 12
|
||||||
|
despawnMinY: -10
|
||||||
|
|||||||
@@ -2521,10 +2521,10 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::Spawner
|
m_EditorClassIdentifier: Assembly-CSharp::Spawner
|
||||||
objectToSpawn: {fileID: 700000000, guid: 8bf8957665594a718535d06aba0cdee7, type: 3}
|
objectToSpawn: {fileID: 700000000, guid: 8bf8957665594a718535d06aba0cdee7, type: 3}
|
||||||
spawnInterval: 3
|
spawnInterval: 5
|
||||||
maxAlive: 1
|
maxAlive: 1
|
||||||
spawnOnStart: 1
|
spawnOnStart: 1
|
||||||
repeatSpawns: 0
|
repeatSpawns: 1
|
||||||
--- !u!1 &2100000100
|
--- !u!1 &2100000100
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -2569,6 +2569,20 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 44f2fea877e8498fa4898917356fb2e6, type: 3}
|
m_Script: {fileID: 11500000, guid: 44f2fea877e8498fa4898917356fb2e6, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!114 &2100000103
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2100000100}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 4eb1753179e848ed8662b6f039a33df9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
spawner: {fileID: 2100000002}
|
||||||
|
checkInterval: 1
|
||||||
--- !u!1001 &1760117322204329348
|
--- !u!1001 &1760117322204329348
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ public class Spawner : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SpawnNow()
|
||||||
|
{
|
||||||
|
SpawnOnce();
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerator SpawnRoutine()
|
private IEnumerator SpawnRoutine()
|
||||||
{
|
{
|
||||||
// Infinite loop to keep spawning (can be modified)
|
// Infinite loop to keep spawning (can be modified)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class TrickController : MonoBehaviour
|
|||||||
private static readonly List<TrickController> ActiveTricks = new List<TrickController>();
|
private static readonly List<TrickController> ActiveTricks = new List<TrickController>();
|
||||||
private static PlayerPlatformerController[] cachedPlayers = Array.Empty<PlayerPlatformerController>();
|
private static PlayerPlatformerController[] cachedPlayers = Array.Empty<PlayerPlatformerController>();
|
||||||
private static float nextPlayerCacheTime;
|
private static float nextPlayerCacheTime;
|
||||||
|
public static int ActiveCount => ActiveTricks.Count;
|
||||||
|
|
||||||
[SerializeField] private string treatTag = "Interactable";
|
[SerializeField] private string treatTag = "Interactable";
|
||||||
[SerializeField] private float moveSpeed = 3.5f;
|
[SerializeField] private float moveSpeed = 3.5f;
|
||||||
@@ -30,6 +31,9 @@ public class TrickController : MonoBehaviour
|
|||||||
[SerializeField] private float jumpChancePerSecond = 0.5f;
|
[SerializeField] private float jumpChancePerSecond = 0.5f;
|
||||||
[SerializeField] private LayerMask groundMask = ~0;
|
[SerializeField] private LayerMask groundMask = ~0;
|
||||||
[SerializeField] private float groundCheckDistance = 0.05f;
|
[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 Rigidbody2D body;
|
||||||
private Transform target;
|
private Transform target;
|
||||||
@@ -74,6 +78,13 @@ public class TrickController : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var position = transform.position;
|
||||||
|
if (position.x < despawnMinX || position.x > despawnMaxX || position.y < despawnMinY)
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Time.time >= nextTargetTime)
|
if (Time.time >= nextTargetTime)
|
||||||
{
|
{
|
||||||
target = FindNearestTreat();
|
target = FindNearestTreat();
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4eb1753179e848ed8662b6f039a33df9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user