몬스터 플레이어 감지 범위 구현 테스트

This commit is contained in:
Mingu Kim
2025-02-08 18:26:58 +09:00
parent 57eb4abea3
commit 497e1a495b
5 changed files with 3268 additions and 10172 deletions

View File

@@ -11,9 +11,13 @@ namespace TON
public class MonsterBase : MonoBehaviour, IDamage
{
public int id; // 적 고유 ID
public int hp; // HP
public int damage; // 공격력
public float currentHP = 100; // HP
public string name; // 몬스터 명 or 프리팹 명
public string monsterType; // 몬스터 타입 ex : melee, ranged
// public int damage; // 공격력
public float speed = 2; // 이동속도
[SerializeField]
@@ -22,6 +26,8 @@ namespace TON
private Vector3 _direction;
private bool _isWalking;
private bool _isHit;
private bool _isDetect;
private float _currentTime;
[SerializeField]
@@ -32,6 +38,9 @@ namespace TON
[SerializeField]
private GameObject _target;
[SerializeField]
private Collider2D _collider;
public float defencePower;
@@ -45,7 +54,8 @@ namespace TON
_direction = new Vector3(1, 0, 0);
_spriteRenderer.flipX = !(_direction.x > 0);
_collider = GetComponent<Collider2D>();
// TODO: 몬스터 방어력 세팅 임시값
defencePower = 10f;
}
@@ -56,7 +66,8 @@ namespace TON
// todo : 타겟 감지 >> 몬스터의 원형 시야 안에 플레이어가 충돌했는지 여부
// todo : 충돌 했으면 attack 전환 (바로 그냥 공격하게 따라가지 말고)
// todo : 시야를 벗어났으면 idle 전환
_isDetect = false;
if (_isWalking)
{
@@ -86,6 +97,11 @@ namespace TON
_isWalking = true;
}
}
if (_isHit)
{
}
_animator.SetBool("Walk", _isWalking); // 걷기 애니메이션
}
@@ -103,13 +119,26 @@ namespace TON
public void ApplyDamage(float damage)
{
// TODO: 몬스터 피해 값 코드
// 몬스터 피해 값 코드
// 체력이 감소되는 부분
// 몬스터 죽고 파괴되는 부분
// 피격됐을때 애니메이션
float prevHP = currentHP;
currentHP -= damage;
if (prevHP > 0 && currentHP <= 0)
{
_animator.SetBool("Die", true); // 몬스터 죽는 애니메이션 트리거
Destroy(gameObject); // 몬스터 파괴
}
else if (prevHP > 0 && currentHP > 0)
{
_animator.SetBool("Hit", true); // 피격 애니메이션
}
}
void MonsterAttack()
void MonsterAttack(GameObject player)
{
// 임시 반영 수정 예정
DamageCalculator damageCalculator = new DamageCalculator();
@@ -123,5 +152,16 @@ namespace TON
Debug.Log($" 몬스터 공격! 최종 데미지: {damage}");
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.CompareTag("Player"))
{
_isDetect = true;
_animator.SetBool("Attack", _isDetect); // 공격 애니메이션 재생
MonsterAttack(other.gameObject); // 플레이어에게 공격
Debug.Log("감지됨");
}
}
}
}

View File

@@ -12,6 +12,7 @@
"com.unity.cinemachine": "2.10.3",
"com.unity.collab-proxy": "2.6.0",
"com.unity.feature.development": "1.0.1",
"com.unity.ide.rider": "3.0.34",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.6",
"com.unity.ugui": "1.0.0",

View File

@@ -135,7 +135,7 @@
},
"com.unity.ext.nunit": {
"version": "1.0.6",
"depth": 2,
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
@@ -155,8 +155,8 @@
}
},
"com.unity.ide.rider": {
"version": "3.0.28",
"depth": 1,
"version": "3.0.34",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.6"