Adding treat eating cooldown
This commit is contained in:
@@ -41,7 +41,7 @@
|
|||||||
"path": "<Gamepad>/leftStick",
|
"path": "<Gamepad>/leftStick",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Move",
|
"action": "Move",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": false
|
"isPartOfComposite": false
|
||||||
@@ -214,7 +214,7 @@
|
|||||||
{
|
{
|
||||||
"name": "",
|
"name": "",
|
||||||
"id": "b3f66d0b-7751-423f-908b-a11c5bd95930",
|
"id": "b3f66d0b-7751-423f-908b-a11c5bd95930",
|
||||||
"path": "<Gamepad>/buttonNorth",
|
"path": "<Gamepad>/buttonEast",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": "Gamepad",
|
"groups": "Gamepad",
|
||||||
@@ -285,7 +285,7 @@
|
|||||||
"path": "<Gamepad>/buttonEast",
|
"path": "<Gamepad>/buttonEast",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Interact",
|
"action": "Interact",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": false
|
"isPartOfComposite": false
|
||||||
@@ -313,6 +313,15 @@
|
|||||||
"processors": "",
|
"processors": "",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"initialStateCheck": false
|
"initialStateCheck": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Interact",
|
||||||
|
"type": "Button",
|
||||||
|
"id": "c8a2c7b1-7c4b-4b6c-9c67-5f4a2a6f8c1c",
|
||||||
|
"expectedControlType": "",
|
||||||
|
"processors": "",
|
||||||
|
"interactions": "",
|
||||||
|
"initialStateCheck": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bindings": [
|
"bindings": [
|
||||||
@@ -337,6 +346,17 @@
|
|||||||
"action": "Jump",
|
"action": "Jump",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": 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": "",
|
"processors": "",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"initialStateCheck": false
|
"initialStateCheck": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Interact",
|
||||||
|
"type": "Button",
|
||||||
|
"id": "e2e9b2d1-8f44-4a8b-b5a0-4f1d6a7c9b2a",
|
||||||
|
"expectedControlType": "",
|
||||||
|
"processors": "",
|
||||||
|
"interactions": "",
|
||||||
|
"initialStateCheck": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bindings": [
|
"bindings": [
|
||||||
@@ -385,6 +414,17 @@
|
|||||||
"action": "Jump",
|
"action": "Jump",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": 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",
|
"path": "<Gamepad>/leftStick/up",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -512,7 +552,7 @@
|
|||||||
"path": "<Gamepad>/rightStick/up",
|
"path": "<Gamepad>/rightStick/up",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -523,7 +563,7 @@
|
|||||||
"path": "<Gamepad>/leftStick/down",
|
"path": "<Gamepad>/leftStick/down",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -534,7 +574,7 @@
|
|||||||
"path": "<Gamepad>/rightStick/down",
|
"path": "<Gamepad>/rightStick/down",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -545,7 +585,7 @@
|
|||||||
"path": "<Gamepad>/leftStick/left",
|
"path": "<Gamepad>/leftStick/left",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -556,7 +596,7 @@
|
|||||||
"path": "<Gamepad>/rightStick/left",
|
"path": "<Gamepad>/rightStick/left",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -567,7 +607,7 @@
|
|||||||
"path": "<Gamepad>/leftStick/right",
|
"path": "<Gamepad>/leftStick/right",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -578,7 +618,7 @@
|
|||||||
"path": "<Gamepad>/rightStick/right",
|
"path": "<Gamepad>/rightStick/right",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
@@ -589,7 +629,7 @@
|
|||||||
"path": "<Gamepad>/dpad",
|
"path": "<Gamepad>/dpad",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"processors": "",
|
"processors": "",
|
||||||
"groups": ";Gamepad",
|
"groups": "Gamepad",
|
||||||
"action": "Navigate",
|
"action": "Navigate",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": false
|
"isPartOfComposite": false
|
||||||
@@ -967,4 +1007,4 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2843,6 +2843,7 @@ MonoBehaviour:
|
|||||||
spawnInterval: 3
|
spawnInterval: 3
|
||||||
maxAlive: 1
|
maxAlive: 1
|
||||||
spawnOnStart: 1
|
spawnOnStart: 1
|
||||||
|
repeatSpawns: 0
|
||||||
--- !u!1660057539 &9223372036854775807
|
--- !u!1660057539 &9223372036854775807
|
||||||
SceneRoots:
|
SceneRoots:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -83,31 +83,33 @@ public class PlayerPickupController : MonoBehaviour
|
|||||||
Debug.Log(colliders.Length + " colliders found in range");
|
Debug.Log(colliders.Length + " colliders found in range");
|
||||||
foreach (var col in colliders)
|
foreach (var col in colliders)
|
||||||
{
|
{
|
||||||
if (col.CompareTag("Interactable"))
|
if (!col.TryGetComponent<TrickController>(out var trick) && !col.CompareTag("Interactable"))
|
||||||
{
|
{
|
||||||
heldObject = col.gameObject;
|
continue;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
public float spawnInterval = 1f;
|
||||||
[SerializeField] private int maxAlive = 0;
|
[SerializeField] private int maxAlive = 0;
|
||||||
[SerializeField] private bool spawnOnStart = true;
|
[SerializeField] private bool spawnOnStart = true;
|
||||||
|
[SerializeField] private bool repeatSpawns = true;
|
||||||
|
|
||||||
private readonly List<GameObject> spawned = new List<GameObject>();
|
private readonly List<GameObject> spawned = new List<GameObject>();
|
||||||
|
|
||||||
@@ -23,8 +24,11 @@ public class Spawner : MonoBehaviour
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
// Start the spawning process using a Coroutine
|
if (repeatSpawns)
|
||||||
StartCoroutine(SpawnRoutine());
|
{
|
||||||
|
// Start the spawning process using a Coroutine
|
||||||
|
StartCoroutine(SpawnRoutine());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator SpawnRoutine()
|
private IEnumerator SpawnRoutine()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class TrickController : MonoBehaviour
|
|||||||
[SerializeField] private float targetRefreshInterval = 0.4f;
|
[SerializeField] private float targetRefreshInterval = 0.4f;
|
||||||
[SerializeField] private float consumeDistance = 0.35f;
|
[SerializeField] private float consumeDistance = 0.35f;
|
||||||
[SerializeField] private float wanderInterval = 1.2f;
|
[SerializeField] private float wanderInterval = 1.2f;
|
||||||
|
[SerializeField] private float consumeCooldown = 1.5f;
|
||||||
[SerializeField] private TrickController trickPrefab;
|
[SerializeField] private TrickController trickPrefab;
|
||||||
|
|
||||||
private Rigidbody2D body;
|
private Rigidbody2D body;
|
||||||
@@ -18,6 +19,7 @@ public class TrickController : MonoBehaviour
|
|||||||
private Vector2 wanderDirection;
|
private Vector2 wanderDirection;
|
||||||
private float nextWanderTime;
|
private float nextWanderTime;
|
||||||
private bool isCarried;
|
private bool isCarried;
|
||||||
|
private float nextConsumeTime;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@@ -136,6 +138,11 @@ public class TrickController : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Time.time < nextConsumeTime)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var hits = Physics2D.OverlapCircleAll(transform.position, consumeDistance);
|
var hits = Physics2D.OverlapCircleAll(transform.position, consumeDistance);
|
||||||
for (var i = 0; i < hits.Length; i++)
|
for (var i = 0; i < hits.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -152,6 +159,7 @@ public class TrickController : MonoBehaviour
|
|||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
SpawnTrick(spawnPosition);
|
SpawnTrick(spawnPosition);
|
||||||
|
nextConsumeTime = Time.time + consumeCooldown;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user