Adding treat eating cooldown
This commit is contained in:
@@ -83,31 +83,33 @@ public class PlayerPickupController : MonoBehaviour
|
||||
Debug.Log(colliders.Length + " colliders found in range");
|
||||
foreach (var col in colliders)
|
||||
{
|
||||
if (col.CompareTag("Interactable"))
|
||||
if (!col.TryGetComponent<TrickController>(out var trick) && !col.CompareTag("Interactable"))
|
||||
{
|
||||
heldObject = col.gameObject;
|
||||
|
||||
// Parent the object to the HoldPoint and reset its local position
|
||||
heldObject.transform.SetParent(holdPoint);
|
||||
heldObject.transform.localPosition = Vector3.zero;
|
||||
heldObject.transform.localRotation = Quaternion.identity;
|
||||
|
||||
// Disable physics so it doesn't fall or collide with the player
|
||||
if (heldObject.TryGetComponent<Rigidbody2D>(out Rigidbody2D rb))
|
||||
{
|
||||
rb.bodyType = RigidbodyType2D.Kinematic;
|
||||
rb.gravityScale = 0;
|
||||
rb.mass = 0;
|
||||
}
|
||||
|
||||
if (heldObject.TryGetComponent<TrickController>(out var trick))
|
||||
{
|
||||
trick.SetCarried(true);
|
||||
}
|
||||
|
||||
if (col != null) col.enabled = false;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
heldObject = col.gameObject;
|
||||
|
||||
// Parent the object to the HoldPoint and reset its local position
|
||||
heldObject.transform.SetParent(holdPoint);
|
||||
heldObject.transform.localPosition = Vector3.zero;
|
||||
heldObject.transform.localRotation = Quaternion.identity;
|
||||
|
||||
// Disable physics so it doesn't fall or collide with the player
|
||||
if (heldObject.TryGetComponent<Rigidbody2D>(out Rigidbody2D rb))
|
||||
{
|
||||
rb.bodyType = RigidbodyType2D.Kinematic;
|
||||
rb.gravityScale = 0;
|
||||
rb.mass = 0;
|
||||
}
|
||||
|
||||
if (trick != null)
|
||||
{
|
||||
trick.SetCarried(true);
|
||||
}
|
||||
|
||||
if (col != null) col.enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ public class Spawner : MonoBehaviour
|
||||
public float spawnInterval = 1f;
|
||||
[SerializeField] private int maxAlive = 0;
|
||||
[SerializeField] private bool spawnOnStart = true;
|
||||
[SerializeField] private bool repeatSpawns = true;
|
||||
|
||||
private readonly List<GameObject> spawned = new List<GameObject>();
|
||||
|
||||
@@ -23,8 +24,11 @@ public class Spawner : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Start the spawning process using a Coroutine
|
||||
StartCoroutine(SpawnRoutine());
|
||||
if (repeatSpawns)
|
||||
{
|
||||
// Start the spawning process using a Coroutine
|
||||
StartCoroutine(SpawnRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator SpawnRoutine()
|
||||
|
||||
@@ -10,6 +10,7 @@ public class TrickController : MonoBehaviour
|
||||
[SerializeField] private float targetRefreshInterval = 0.4f;
|
||||
[SerializeField] private float consumeDistance = 0.35f;
|
||||
[SerializeField] private float wanderInterval = 1.2f;
|
||||
[SerializeField] private float consumeCooldown = 1.5f;
|
||||
[SerializeField] private TrickController trickPrefab;
|
||||
|
||||
private Rigidbody2D body;
|
||||
@@ -18,6 +19,7 @@ public class TrickController : MonoBehaviour
|
||||
private Vector2 wanderDirection;
|
||||
private float nextWanderTime;
|
||||
private bool isCarried;
|
||||
private float nextConsumeTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -136,6 +138,11 @@ public class TrickController : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time < nextConsumeTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var hits = Physics2D.OverlapCircleAll(transform.position, consumeDistance);
|
||||
for (var i = 0; i < hits.Length; i++)
|
||||
{
|
||||
@@ -152,6 +159,7 @@ public class TrickController : MonoBehaviour
|
||||
target = null;
|
||||
}
|
||||
SpawnTrick(spawnPosition);
|
||||
nextConsumeTime = Time.time + consumeCooldown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user