BloodAndGore/Assets/Scripts/Enemies/Health.cs

30 lines
1.0 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2019-08-14 16:17:48 +02:00
using Saltosion.OneWeapon.Player;
using Saltosion.OneWeapon.Effects;
2019-08-14 16:17:48 +02:00
namespace Saltosion.OneWeapon.Enemies {
2019-08-14 22:20:54 +02:00
[RequireComponent(typeof(Explodable))]
2019-08-07 20:03:51 +02:00
public class Health : MonoBehaviour {
public float MaxHealth;
public float CurrentHealth;
private PlayerFun PlayerFun;
2019-08-14 22:20:54 +02:00
private Explodable Explodable;
private void Start() {
PlayerFun = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerFun>();
2019-08-14 22:20:54 +02:00
Explodable = GetComponent<Explodable>();
}
public void Damage(float amount, Vector2 fromDirection, bool causedByPlayerAttack) {
2019-08-14 23:27:14 +02:00
DebrisLauncher.Splatter(DebrisType.Blood, transform.position, -fromDirection, (int)(amount), 100f, 100);
CurrentHealth -= amount * (1 + (causedByPlayerAttack ? PlayerFun.CurrentDamageBoost : 0.0f));
2019-08-14 22:20:54 +02:00
if (CurrentHealth <= 0) {
Explodable.Explode(true, causedByPlayerAttack);
2019-08-14 22:20:54 +02:00
}
}
}
}