48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Invector;
|
|
using UnityEngine;
|
|
|
|
public class AutoDestroy : MonoBehaviour
|
|
{
|
|
public int damageAmount = 30;
|
|
void Start()
|
|
{
|
|
Destroy(gameObject,2f);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
// Debug: Log tên và tag của bất cứ thứ gì đạn chạm vào
|
|
Debug.Log(
|
|
$"Laser collided with: {other.name} | Tag: {other.tag} | Layer: {LayerMask.LayerToName(other.gameObject.layer)}");
|
|
|
|
// Kiểm tra nếu trúng Player
|
|
if (other.CompareTag("Player") || other.GetComponentInParent<vIHealthController>() != null)
|
|
{
|
|
var healthController = other.GetComponentInParent<vIHealthController>();
|
|
|
|
if (healthController != null)
|
|
{
|
|
Debug.Log(
|
|
$"<color=red>HIT PLAYER!</color> Found health controller on {healthController.gameObject.name}. Applying {damageAmount} damage.");
|
|
var damage = new vDamage(damageAmount);
|
|
damage.sender = transform;
|
|
damage.hitPosition = transform.position;
|
|
healthController.TakeDamage(damage);
|
|
}
|
|
|
|
// Luôn phá hủy đạn khi trúng Player
|
|
Impact();
|
|
|
|
}
|
|
}
|
|
|
|
private void Impact()
|
|
{
|
|
|
|
|
|
// Phá hủy đạn ngay lập tức
|
|
Destroy(gameObject);
|
|
}
|
|
}
|