creative-jam-20/Assets/Scripts/DimensionController.cs
2022-05-15 13:08:52 -04:00

38 lines
828 B
C#

using UnityEngine;
public class DimensionController : MonoBehaviour
{
public const int STARTING_HP = 25;
[SerializeField] private int dimensionId;
private float _hp;
private float _maxHp;
[SerializeField] private LayerMask mask;
private void Start()
{
_maxHp = STARTING_HP;
_hp = _maxHp;
}
private void OnTriggerEnter(Collider other)
{
if (_hp <= 0) { return; }
var enemy = other.GetComponent<Enemy>();
if (ReferenceEquals(enemy, null)) return;
// Update HP (temp for now)
_hp -= enemy.DamageDealt();
// Destroy projectile
Destroy(other.gameObject);
GameManager.Instance.DealDamage(dimensionId, _hp, _maxHp);
}
public int GetDimensionMask()
{
return mask;
}
}