38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|