update
This commit is contained in:
@@ -1,36 +1,66 @@
|
||||
using UnityEngine;
|
||||
using Hallucinate.Audio;
|
||||
using Invector;
|
||||
|
||||
public class LaserProjectile : MonoBehaviour
|
||||
{
|
||||
public float speed = 5f;
|
||||
public float speed = 15f; // Tăng tốc độ đạn để cảm giác mượt hơn
|
||||
public float lifeTime = 5f;
|
||||
public int damageAmount = 10;
|
||||
|
||||
[Header("Audio")]
|
||||
public string hitSound = "Laser_Hit";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Tự hủy sau một khoảng thời gian nếu không trúng gì
|
||||
Destroy(gameObject, lifeTime);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.position +=
|
||||
transform.forward *
|
||||
speed *
|
||||
Time.deltaTime;
|
||||
// Di chuyển đạn
|
||||
transform.position += transform.forward * speed * Time.deltaTime;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
// 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)
|
||||
{
|
||||
Debug.Log("Player Hit");
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
||||
AudioManager.Instance?.Play(hitSound, position: transform.position);
|
||||
|
||||
Destroy(gameObject);
|
||||
// Phá hủy đạn nếu trúng tường, sàn nhà (mọi thứ không phải trigger khác)
|
||||
if (!other.isTrigger)
|
||||
{
|
||||
Debug.Log("Laser hit an obstacle (Wall/Floor).");
|
||||
Impact();
|
||||
}
|
||||
}
|
||||
|
||||
private void Impact()
|
||||
{
|
||||
// Chạy âm thanh
|
||||
AudioManager.Instance?.Play(hitSound, position: transform.position);
|
||||
|
||||
// Phá hủy đạn ngay lập tức
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -318,6 +318,14 @@ namespace Invector.vCharacterController
|
||||
currentStaminaRecoveryDelay = 2f;
|
||||
}
|
||||
|
||||
public override void TakeDamage(vDamage damage)
|
||||
{
|
||||
Debug.Log($"Player TakeDamage called. Damage: {damage.damageValue}. Current Health before: {currentHealth}");
|
||||
base.TakeDamage(damage);
|
||||
Debug.Log($"Player Health after: {currentHealth}");
|
||||
// Additional logic for player-specific damage handling can be added here
|
||||
}
|
||||
|
||||
|
||||
#region Check Action Triggers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user