Skip to content

Commit

Permalink
feat: persistent shark damage on stay
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoneerC committed Sep 24, 2024
1 parent 186c292 commit 2509f6f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Assets/Scenes/Reparation.unity
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: ee9ab2a2c8115bf449c61728aee6099d, type: 3}
propertyPath: m_LocalPosition.y
value: 15.92215
value: 16.1
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: ee9ab2a2c8115bf449c61728aee6099d, type: 3}
propertyPath: m_LocalPosition.z
Expand Down Expand Up @@ -654,7 +654,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: 7e868a49e1cfe56428ce4704afc2ee8a, type: 3}
propertyPath: m_LocalPosition.y
value: 16.305462
value: 16.4
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: 7e868a49e1cfe56428ce4704afc2ee8a, type: 3}
propertyPath: m_LocalPosition.z
Expand Down Expand Up @@ -2439,7 +2439,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: 8cab0fc9be2d12741a4e26984b05ffdb, type: 3}
propertyPath: m_LocalPosition.y
value: 11.359894
value: 11.8
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: 8cab0fc9be2d12741a4e26984b05ffdb, type: 3}
propertyPath: m_LocalPosition.z
Expand Down Expand Up @@ -6757,7 +6757,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: d86e05db9db58774e9a8b15bf72e7a08, type: 3}
propertyPath: m_LocalPosition.y
value: 16.466646
value: 16.6
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: d86e05db9db58774e9a8b15bf72e7a08, type: 3}
propertyPath: m_LocalPosition.z
Expand Down Expand Up @@ -26800,7 +26800,7 @@ Transform:
m_GameObject: {fileID: 1522474813}
serializedVersion: 2
m_LocalRotation: {x: -0.17842343, y: -0, z: -0, w: 0.9839538}
m_LocalPosition: {x: -2.67, y: -5.96, z: -25.12}
m_LocalPosition: {x: -2.67, y: -5.59, z: -25.12}
m_LocalScale: {x: 2.486358, y: 1, z: 2.9054}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -30632,7 +30632,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: 6dbd51e7d3a3e82438c922e2b8870d37, type: 3}
propertyPath: m_LocalPosition.y
value: 16.518383
value: 16.6
objectReference: {fileID: 0}
- target: {fileID: -5819118886272102141, guid: 6dbd51e7d3a3e82438c922e2b8870d37, type: 3}
propertyPath: m_LocalPosition.z
Expand Down
30 changes: 30 additions & 0 deletions Assets/Scripts/Health.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Health : MonoBehaviour

public Text healthText;

private Coroutine _damageOverTimeCoroutine;

private void Start()
{
damageValues.Add(50);
Expand All @@ -27,6 +29,8 @@ private void OnTriggerEnter(Collider other)
if (other.CompareTag("Chelicerate"))
{
TakeDamage();

_damageOverTimeCoroutine ??= StartCoroutine(DamageOverTime(3f, 0.5f));
}

if (!other.CompareTag("Kit") || !(health < 100f)) return;
Expand All @@ -35,6 +39,13 @@ private void OnTriggerEnter(Collider other)
Destroy(other.gameObject);
}

private void OnTriggerExit(Collider other)
{
if (!other.CompareTag("Chelicerate") || _damageOverTimeCoroutine == null) return;
StopCoroutine(_damageOverTimeCoroutine);
_damageOverTimeCoroutine = null;
}

private void TakeDamage()
{
if (damageValues.Count > 0)
Expand All @@ -61,6 +72,24 @@ private void TakeDamage()
}
}

private IEnumerator DamageOverTime(float damageAmount, float interval)
{
while (true)
{
health -= damageAmount;
health = Mathf.Max(health, 0f);

if (health <= 0)
{
Die();
break;
}

UpdateHealthUI();
yield return new WaitForSeconds(interval);
}
}

private IEnumerator Heal(float duration)
{
var targetHealth = Mathf.Min(health + 50f, 100f);
Expand Down Expand Up @@ -89,5 +118,6 @@ private void UpdateHealthUI()
private void Die()
{
// Handle death logic here
Debug.Log("Player died!");
}
}

0 comments on commit 2509f6f

Please sign in to comment.