Adding treat eating cooldown

This commit is contained in:
hz
2026-01-31 19:44:21 -06:00
parent e4e385c5c2
commit 14ec7e81b2
5 changed files with 93 additions and 38 deletions
+53 -13
View File
@@ -41,7 +41,7 @@
"path": "<Gamepad>/leftStick",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Move",
"isComposite": false,
"isPartOfComposite": false
@@ -214,7 +214,7 @@
{
"name": "",
"id": "b3f66d0b-7751-423f-908b-a11c5bd95930",
"path": "<Gamepad>/buttonNorth",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
@@ -285,7 +285,7 @@
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
@@ -313,6 +313,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Interact",
"type": "Button",
"id": "c8a2c7b1-7c4b-4b6c-9c67-5f4a2a6f8c1c",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
@@ -337,6 +346,17 @@
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "c3c7b8ad-6b3b-4a4c-9b0b-1c2f7e9a4d5e",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
}
]
},
@@ -361,6 +381,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Interact",
"type": "Button",
"id": "e2e9b2d1-8f44-4a8b-b5a0-4f1d6a7c9b2a",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
@@ -385,6 +414,17 @@
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b1f0f4f1-2d7a-4c1e-9c6a-8e5b7c9d1a3f",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
}
]
},
@@ -501,7 +541,7 @@
"path": "<Gamepad>/leftStick/up",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -512,7 +552,7 @@
"path": "<Gamepad>/rightStick/up",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -523,7 +563,7 @@
"path": "<Gamepad>/leftStick/down",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -534,7 +574,7 @@
"path": "<Gamepad>/rightStick/down",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -545,7 +585,7 @@
"path": "<Gamepad>/leftStick/left",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -556,7 +596,7 @@
"path": "<Gamepad>/rightStick/left",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -567,7 +607,7 @@
"path": "<Gamepad>/leftStick/right",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -578,7 +618,7 @@
"path": "<Gamepad>/rightStick/right",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
@@ -589,7 +629,7 @@
"path": "<Gamepad>/dpad",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": false
@@ -967,4 +1007,4 @@
]
}
]
}
}
+1
View File
@@ -2843,6 +2843,7 @@ MonoBehaviour:
spawnInterval: 3
maxAlive: 1
spawnOnStart: 1
repeatSpawns: 0
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
+25 -23
View File
@@ -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;
}
}
+6 -2
View File
@@ -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()
+8
View File
@@ -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;
}
}