Files
pgs/Assets/Scripts/HurtboxController.cs

38 lines
1.0 KiB
C#
Raw Permalink Normal View History

2026-02-21 16:58:22 -08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HurtboxController : MonoBehaviour {
[SerializeField] public float activeTime = 1.0f; // Seconds
[SerializeField] public bool dieOnHit = true;
private PlayerMovement playerMovement;
public int power;
private void Awake() {
Invoke("Die", activeTime);
playerMovement = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMovement>();
}
public void Setup(float time, int pwr) {
activeTime = time;
power = pwr;
}
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.CompareTag("Player") && !playerMovement.invincible) {
Debug.Log("Got'cha!");
int damageTaken = power - (int)State.state.stats.cache.totalDef;
playerMovement.TakeDamage(damageTaken);
if (dieOnHit) {
Die();
}
}
}
public void Die() {
Destroy(gameObject);
}
}