Enemy의 이동 및 공격 로직 개선
포탈 추가
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
// Gate.cs
|
||||
public class Gate : MonoBehaviour, IDamageable
|
||||
{
|
||||
[SerializeField] private float maxHealth = 50f;
|
||||
[SerializeField] private float currentHealth = 50f;
|
||||
private float CurrentHealth;
|
||||
|
||||
// 체력이 변경될 때 UI 등에 알리기 위한 이벤트 (Observer 패턴)
|
||||
public static event Action<float> OnHealthChanged;
|
||||
public static event Action OnGateDestroyed;
|
||||
|
||||
void Awake() => currentHealth = maxHealth;
|
||||
|
||||
public void TakeDamage(float amount)
|
||||
{
|
||||
currentHealth -= amount;
|
||||
if (currentHealth <= 0)
|
||||
OnHealthChanged?.Invoke(currentHealth / maxHealth);
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
var obstacle = GetComponent<UnityEngine.AI.NavMeshObstacle>();
|
||||
if(obstacle != null)
|
||||
{
|
||||
obstacle.carving = false;
|
||||
obstacle.enabled = false;
|
||||
}
|
||||
OnGateDestroyed?.Invoke();
|
||||
Destroy(gameObject, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,22 @@ public class Portal : MonoBehaviour
|
||||
// 플레이어 태그 확인 및 쿨타임 체크
|
||||
if (other.CompareTag("Player") && Time.time > _lastTeleportTime + cooldown)
|
||||
{
|
||||
// 상대방 포탈의 쿨타임도 같이 설정해야 무한 루프를 방지함
|
||||
CharacterController cc = other.GetComponent<CharacterController>();
|
||||
|
||||
// 1. 상대방 포탈 쿨타임 설정
|
||||
Portal destPortal = destination.GetComponent<Portal>();
|
||||
if (destPortal != null) destPortal._lastTeleportTime = Time.time;
|
||||
|
||||
_lastTeleportTime = Time.time;
|
||||
|
||||
// 플레이어 위치 이동
|
||||
// CharacterController나 Rigidbody를 사용 중이라면 이동 방식에 주의
|
||||
other.transform.position = destination.position;
|
||||
// 2. CharacterController 잠시 끄기 (중요!)
|
||||
if (cc != null) cc.enabled = false;
|
||||
|
||||
// 3. 위치 이동
|
||||
other.transform.position = destination.position;
|
||||
Debug.Log("Teleported to " + destination.name);
|
||||
|
||||
// 4. 다시 켜기
|
||||
if (cc != null) cc.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user