Fixed blood and also made blood better

This commit is contained in:
Sveske Juice 2024-02-03 17:26:11 -08:00
parent 8f7d31d742
commit 5dc812c55f
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyAnimationHandler : MonoBehaviour
{
@ -15,6 +16,9 @@ public class EnemyAnimationHandler : MonoBehaviour
}
void EnemyDie()
{
GetComponent<Collider2D>().enabled = false;
GetComponent<NavMeshAgent>().enabled = false;
StartCoroutine(AnimationDie());
}

View File

@ -29,6 +29,7 @@ public class EnemyPathFinding : MonoBehaviour
Vector2 dir = closestTarget.position - transform.position;
if (Physics2D.Raycast(transform.position, dir.normalized, ropeDistCheck, ropeCheckMask)) return;
agent.SetDestination(closestTarget.position);
}

View File

@ -6,6 +6,7 @@ using UnityUtils;
public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
{
[SerializeField] private bool onlyCallZeroHealthOnce = true;
[SerializeField] float maxHealth = 100;
[SerializeField] float damageTickDelay = 0.25f;
@ -26,6 +27,8 @@ public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
[SerializeField]
float squezeDamageScalor = 1f;
bool alreadyReachedZero = false;
void Awake()
{
currentHealth = maxHealth;
@ -62,12 +65,19 @@ public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
accumulatedDamageInTick += damage;
if (currentHealth <= 0) {
if (alreadyReachedZero && onlyCallZeroHealthOnce) return;
alreadyReachedZero = true;
// Make sure to flush accumulated when dying
if (accumulatedDamageInTick > 1f)
OnHealthChangeAtPos?.Invoke(transform.position.Add(y: 2f), accumulatedDamageInTick);
OnHealthZero?.Invoke();
BloodComputeShader.Instance.createBlood(transform.position, (int)(maxHealth *maxHealth * BloodComputeShader.Instance.scoreMult), maxHealth / 8.0f);
int blood = (int)(maxHealth * 100.0f * BloodComputeShader.Instance.scoreMult);
BloodComputeShader.Instance.createBlood(transform.position, blood/2, maxHealth / 8.0f);
BloodComputeShader.Instance.createBlood(transform.position, blood / 2, maxHealth / 8.0f);
}
}